From: Viktor Szakats Date: Wed, 7 Jan 2026 19:26:28 +0000 (+0100) Subject: curl: limit Windows-specific code to Windows builds, other tidy-ups X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df7718b5cf61de2e4c1f0452957cc41e0034c576;p=thirdparty%2Fcurl.git curl: limit Windows-specific code to Windows builds, other tidy-ups 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 --- diff --git a/src/tool_cb_rea.c b/src/tool_cb_rea.c index 5ad4f7e0b2..4683f70691 100644 --- a/src/tool_cb_rea.c +++ b/src/tool_cb_rea.c @@ -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 */ diff --git a/src/tool_operate.c b/src/tool_operate.c index 19462e0f0c..0b7b307728 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -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;