]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_cb_hdr: use the file descriptor instead of calling fileno() again
authorDaniel Stenberg <daniel@haxx.se>
Fri, 27 Mar 2026 15:37:15 +0000 (16:37 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 27 Mar 2026 15:50:28 +0000 (16:50 +0100)
Follow-up to 6041b9b11b904c6430

Closes #21126

src/tool_cb_hdr.c

index 4ee777e1c04807e84a215b280697ba99ee15e4e8..747a8ac2c60ef0c8605eabd5c3c2454e1f7a2dce 100644 (file)
@@ -266,15 +266,13 @@ static size_t save_etag(const char *etag_h, const char *endp,
       curlx_struct_stat file;
       int fd = fileno(etag_save->stream);
 
+      /* Truncate regular files to avoid stale etag content */
       if((fd != -1) &&
          !curlx_fstat(fd, &file) &&
-         (S_ISREG(file.st_mode))) {
-        /*
-         * Truncate regular files to avoid stale etag content.
-         */
-        if(ftruncate(fileno(etag_save->stream), 0))
-          return CURL_WRITEFUNC_ERROR;
-      }
+         (S_ISREG(file.st_mode) &&
+          ftruncate(fd, 0)))
+        return CURL_WRITEFUNC_ERROR;
+
       fwrite(etag_h, 1, etag_length, etag_save->stream);
       /* terminate with newline */
       fputc('\n', etag_save->stream);