]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
fopen: optimize
authorSaltyMilk <soufiane.elmelcaoui@gmail.com>
Mon, 10 Jul 2023 19:43:28 +0000 (21:43 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 11 Jul 2023 17:43:51 +0000 (19:43 +0200)
Closes #11419

lib/fopen.c

index c9c9e3d6e73a266377026773ce2781aa630f747a..b6e3cadddef656ee7b77d406dba02ca888002382 100644 (file)
@@ -56,13 +56,13 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
   int fd = -1;
   *tempname = NULL;
 
-  if(stat(filename, &sb) == -1 || !S_ISREG(sb.st_mode)) {
-    /* a non-regular file, fallback to direct fopen() */
-    *fh = fopen(filename, FOPEN_WRITETEXT);
-    if(*fh)
-      return CURLE_OK;
+  *fh = fopen(filename, FOPEN_WRITETEXT);
+  if(!*fh)
     goto fail;
-  }
+  if(fstat(fileno(*fh), &sb) == -1 || !S_ISREG(sb.st_mode))
+    return CURLE_OK;
+  fclose(*fh);
+  *fh = NULL;
 
   result = Curl_rand_hex(data, randsuffix, sizeof(randsuffix));
   if(result)