]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: limit Windows-specific code to Windows builds, other tidy-ups
authorViktor Szakats <commit@vsz.me>
Wed, 7 Jan 2026 19:26:28 +0000 (20:26 +0100)
committerViktor Szakats <commit@vsz.me>
Fri, 9 Jan 2026 08:42:01 +0000 (09:42 +0100)
Prior to this patch, some Windows logic, including a Windows-specific
warning message was compiled in for all platforms.

Also:
- fix double space in warning message on UWP.
- formatting.

Follow-up to 9a2663322c330ff11275abafd612e9c99407a94a #17572

Closes #20213

src/tool_cb_rea.c
src/tool_operate.c

index 5ad4f7e0b21248c2c8210d5cb16be4b5b628aa2e..4683f70691ffc5b8155c622eb56522ed2eb806c3 100644 (file)
@@ -113,13 +113,14 @@ size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
 #endif
   }
 
+#ifdef _WIN32
   /* If we are on Windows, and using `-T .`, then per->infd points to a socket
    connected to stdin via a reader thread, and needs to be read with recv()
    Make sure we are in non-blocking mode and infd is not regular stdin
    On Linux per->infd should be stdin (0) and the block below should not
    execute */
   if(per->uploadfile && !strcmp(per->uploadfile, ".") && per->infd > 0) {
-#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
+#ifndef CURL_WINDOWS_UWP
     rc = recv(per->infd, buffer, curlx_uztosi(sz * nmemb), 0);
     if(rc < 0) {
       if(SOCKERRNO == SOCKEWOULDBLOCK) {
@@ -131,11 +132,13 @@ size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
       rc = 0;
     }
 #else
-    warnf("per->infd != 0: FD == %d. This behavior"
-          " is only supported on desktop Windows", per->infd);
+    warnf("per->infd != 0: FD == %d. "
+          "This behavior is only supported on desktop Windows", per->infd);
 #endif
   }
-  else {
+  else
+#endif
+  {
     rc = read(per->infd, buffer, sz * nmemb);
     if(rc < 0) {
       if(errno == EAGAIN) {
@@ -147,6 +150,7 @@ size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
       rc = 0;
     }
   }
+
   if((per->uploadfilesize != -1) &&
      (per->uploadedsofar + rc > per->uploadfilesize)) {
     /* do not allow uploading more than originally set out to do */
index 19462e0f0cb25234bb2dcf3bf6157e1aef79e4fd..0b7b307728787c2b132ee5d5b031e3eb2d75e2cb 100644 (file)
@@ -607,22 +607,21 @@ static CURLcode post_per_transfer(struct per_transfer *per,
   if(!curl || !config)
     return result;
 
+#ifdef _WIN32
   if(per->uploadfile) {
     if(!strcmp(per->uploadfile, ".") && per->infd > 0) {
-#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
+#ifndef CURL_WINDOWS_UWP
       sclose(per->infd);
 #else
-      warnf("Closing per->infd != 0: FD == "
-            "%d. This behavior is only supported on desktop "
-            " Windows", per->infd);
+      warnf("Closing per->infd != 0: FD == %d. "
+            "This behavior is only supported on desktop Windows", per->infd);
 #endif
     }
   }
-  else {
-    if(per->infdopen) {
+  else
+#endif
+    if(per->infdopen)
       close(per->infd);
-    }
-  }
 
   if(per->skip)
     goto skip;