]> granicus.if.org Git - curl/commitdiff
Using fdopen() is a more correct way to implement the CURLOPT_NEW_FILE_PREMS
authorJames Housley <jim@thehousleys.net>
Thu, 28 Jun 2007 11:11:29 +0000 (11:11 +0000)
committerJames Housley <jim@thehousleys.net>
Thu, 28 Jun 2007 11:11:29 +0000 (11:11 +0000)
file.c, but the debug interface was missing.  This adds the routines needed
to make the memory debuging work for fdopen().

lib/file.c
lib/memdebug.c
lib/memdebug.h
tests/memanalyze.pl

index cec98986b1239e624bd8798057cb216f835c11f8..4cab1f1b9caebcaf52d3b4cdfc0cdc6e2a7e1f46 100644 (file)
@@ -231,8 +231,7 @@ static CURLcode file_upload(struct connectdata *conn)
       failf(data, "Can't open %s for writing", file->path);
       return CURLE_WRITE_ERROR;
     }
-    close(fd);
-    fp = fopen(file->path, "wb");
+    fp = fdopen(fd, "wb");
   }
 
   if(!fp) {
index 582387cf9ceb533df658ea090025164f1bae0573..2eb4c5afb90f374280d089bfa72c750f1e1b596a 100644 (file)
@@ -280,6 +280,16 @@ FILE *curl_fopen(const char *file, const char *mode,
   return res;
 }
 
+FILE *curl_fdopen(int filedes, const char *mode,
+                  int line, const char *source)
+{
+  FILE *res=(fdopen)(filedes, mode);
+  if(logfile)
+    fprintf(logfile, "FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n",
+            source, line, filedes, mode, res);
+  return res;
+}
+
 int curl_fclose(FILE *file, int line, const char *source)
 {
   int res;
index a4ce7e59a8e8bc2522fa234c7da476004ee2821b..4e50ad1bbb172844dab184482e2a9e48d481376d 100644 (file)
@@ -67,6 +67,8 @@ CURL_EXTERN int curl_accept(int s, void *addr, void *addrlen,
 /* FILE functions */
 CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
                              const char *source);
+CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line,
+                              const char *source);
 CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
 
 #ifndef MEMDEBUG_NODEFINES
@@ -117,6 +119,8 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
 
 #undef fopen
 #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
+#undef fdopen
+#define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__)
 #define fclose(file) curl_fclose(file,__LINE__,__FILE__)
 
 #endif /* MEMDEBUG_NODEFINES */
index b6bc967149c11a5222b0622bca0eea593be83133..763f9a3b93db408c3bc48eb87f9ded633efa5d75 100755 (executable)
@@ -237,7 +237,7 @@ while(<FILE>) {
         $linenum = $2;
         $function = $3;
 
-        if($function =~ /fopen\(\"([^\"]*)\",\"([^\"]*)\"\) = (\(nil\)|0x([0-9a-f]*))/) {
+        if($function =~ /f[d]*open\(\"([^\"]*)\",\"([^\"]*)\"\) = (\(nil\)|0x([0-9a-f]*))/) {
             if($3 eq "(nil)") {
                 ;
             }