file: use fdopen() for uploaded files if available
authorKamil Dudka <kdudka@redhat.com>
Mon, 30 Jul 2012 12:20:07 +0000 (14:20 +0200)
committerKamil Dudka <kdudka@redhat.com>
Mon, 30 Jul 2012 13:04:38 +0000 (15:04 +0200)
It eliminates noisy events when using inotify and fixes a TOCTOU issue.

Bug: https://bugzilla.redhat.com/844385

lib/file.c

index 4447c73..1025022 100644 (file)
@@ -351,8 +351,12 @@ static CURLcode file_upload(struct connectdata *conn)
       failf(data, "Can't open %s for writing", file->path);
       return CURLE_WRITE_ERROR;
     }
+#ifdef HAVE_FDOPEN
+    fp = fdopen(fd, "wb");
+#else
     close(fd);
     fp = fopen(file->path, "wb");
+#endif
   }
 
   if(!fp) {