- if ((rrd_file = fopen(file_name,"wb")) == NULL ) {
- rrd_set_error("creating '%s': %s",file_name,strerror(errno));
- rrd_free(rrd);
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
+ fdflags = O_RDWR|O_BINARY|O_CREAT;
+#else
+ fdflags = O_WRONLY|O_CREAT;
+#endif
+ if (force_overwrite == 0) {
+ fdflags |= O_EXCL;
+ }
+ fd = open(file_name,fdflags,0666);
+ if (fd == -1 || (rrd_file = fdopen(fd,"wb")) == NULL) {
+ rrd_set_error("creating '%s': %s",file_name,rrd_strerror(errno));
+ if (fd != -1)
+ close(fd);