added --no-overwrite option to rrdtool create. It prevents rrdtool from clobbering...
[rrdtool.git] / src / rrd_open.c
index d09f640..0939e7c 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * RRDtool 1.3.2  Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.4.2  Copyright by Tobi Oetiker, 1997-2009
  *****************************************************************************
  * rrd_open.c  Open an RRD File
  *****************************************************************************
@@ -172,6 +172,9 @@ rrd_file_t *rrd_open(
         if (rdwr & RRD_CREAT) {
             flags |= (O_CREAT | O_TRUNC);
         }
+        if (rdwr & RRD_EXCL) {
+            flags |= O_EXCL;
+        }
     }
     if (rdwr & RRD_READAHEAD) {
 #ifdef MAP_POPULATE
@@ -216,7 +219,10 @@ rrd_file_t *rrd_open(
     } else {
         rrd_file->file_len = newfile_size;
         lseek(rrd_simple_file->fd, newfile_size - 1, SEEK_SET);
-        write(rrd_simple_file->fd, "\0", 1);   /* poke */
+        if ( write(rrd_simple_file->fd, "\0", 1) == -1){    /* poke */
+            rrd_set_error("write '%s': %s", file_name, rrd_strerror(errno));
+            goto out_close;
+        }
         lseek(rrd_simple_file->fd, 0, SEEK_SET);
     }
 #ifdef HAVE_POSIX_FADVISE