index 75c3722fe24b2680f9c6d4d03fedf4c106ea1628..4e98d53c40be069539ee45c19334f271362f631b 100644 (file)
--- a/program/src/rrd_create.c
+++ b/program/src/rrd_create.c
#include "rrd_hw.h"
#include "rrd_is_thread_safe.h"
+static int opt_no_overwrite = 0;
#ifdef WIN32
#include <fcntl.h>
struct option long_options[] = {
{"start", required_argument, 0, 'b'},
{"step", required_argument, 0, 's'},
+ {"no-overwrite", no_argument, 0, 'O'},
{0, 0, 0, 0}
};
int option_index = 0;
opterr = 0; /* initialize getopt */
while (1) {
- opt = getopt_long(argc, argv, "b:s:", long_options, &option_index);
+ opt = getopt_long(argc, argv, "Ob:s:", long_options, &option_index);
if (opt == EOF)
break;
pdp_step = long_tmp;
break;
+ case 'O':
+ opt_no_overwrite = 1;
+ break;
+
case '?':
if (optopt != 0)
rrd_set_error("unknown option '%c'", optopt);
flags |= O_BINARY;
#endif
+ /* with O_CREAT (above) causes open to fail with EEXIST when if exists */
+ if (opt_no_overwrite) {
+ flags |= O_EXCL;
+ }
+
if ((rrd_file = open(file_name, flags, 0666)) < 0) {
rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
rrd_free2(rrd);