]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
windows: `USE_WINSOCK` to guard winsock2 code (where missing)
authorViktor Szakats <commit@vsz.me>
Tue, 27 Jan 2026 22:53:05 +0000 (23:53 +0100)
committerViktor Szakats <commit@vsz.me>
Wed, 28 Jan 2026 02:27:20 +0000 (03:27 +0100)
Replacing `_WIN32`.

Also:
- tool_doswin: guard possibly non-portable socket code with
  `USE_WINSOCK`. The socket is cast to `HANDLE` and passed to
  win32 API `SetStdHandle(STD_INPUT_HANDLE, ...)`.
- lib/setup-win32.h: move `#undef`s before their `#define` pair.

Closes #20455

lib/curl_setup.h
lib/functypes.h
lib/setup-win32.h
lib/url.c
src/tool_doswin.c
src/tool_operate.c

index f4640b922f3f78164a76b67232b7fa56d4c64058..900264b8ff114a7c09c69c542157ba9ca3371f30 100644 (file)
 
 #ifndef SIZEOF_CURL_SOCKET_T
 /* configure and cmake check and set the define */
-#  ifdef _WIN64
+#  if defined(USE_WINSOCK) && defined(_WIN64)
 #    define SIZEOF_CURL_SOCKET_T 8
 #  else
 /* default guess */
 #endif
 
 #if SIZEOF_CURL_SOCKET_T < 8
-#ifdef _WIN32
+#ifdef USE_WINSOCK
 #  define FMT_SOCKET_T "u"
 #else
 #  define FMT_SOCKET_T "d"
 #endif
-#elif defined(_WIN32)
+#elif defined(USE_WINSOCK)
 #  define FMT_SOCKET_T "zu"
 #else
 #  define FMT_SOCKET_T "qd"
@@ -898,7 +898,7 @@ endings either CRLF or LF so 't' is appropriate.
 
 /* for systems that do not detect this in configure */
 #ifndef CURL_SA_FAMILY_T
-#  ifdef _WIN32
+#  ifdef USE_WINSOCK
 #    define CURL_SA_FAMILY_T ADDRESS_FAMILY
 #  elif defined(HAVE_SA_FAMILY_T)
 #    define CURL_SA_FAMILY_T sa_family_t
index ba754f99b60e677f4334fd4937b2477c7dccb4a0..12dfe17906de5b247d156ae978accb224db509c5 100644 (file)
@@ -37,7 +37,7 @@
    2. For systems with config-*.h files, define them there.
 */
 
-#ifdef _WIN32
+#ifdef USE_WINSOCK
 /* int recv(SOCKET, char *, int, int) */
 #define RECV_TYPE_ARG1 SOCKET
 #define RECV_TYPE_ARG2 char *
index 7aada6a826987a20134e678f42988124abe43062..3ac8c6d5128a01648af38015dbe1d13fac0b3076 100644 (file)
   /* Define to use BSD-style lwIP TCP/IP stack. */
   /* #define USE_LWIPSOCK 1 */
 #  undef HAVE_GETHOSTNAME
-#  undef LWIP_POSIX_SOCKETS_IO_NAMES
-#  undef RECV_TYPE_ARG1
-#  undef RECV_TYPE_ARG3
-#  undef SEND_TYPE_ARG1
-#  undef SEND_TYPE_ARG3
 #  define HAVE_GETHOSTBYNAME_R
 #  define HAVE_GETHOSTBYNAME_R_6
+#  undef LWIP_POSIX_SOCKETS_IO_NAMES
 #  define LWIP_POSIX_SOCKETS_IO_NAMES 0
+#  undef RECV_TYPE_ARG1
 #  define RECV_TYPE_ARG1 int
+#  undef RECV_TYPE_ARG3
 #  define RECV_TYPE_ARG3 size_t
+#  undef SEND_TYPE_ARG1
 #  define SEND_TYPE_ARG1 int
+#  undef SEND_TYPE_ARG3
 #  define SEND_TYPE_ARG3 size_t
 #elif defined(_WIN32)
 #  define USE_WINSOCK 2
+#  include <winsock2.h>
+#  include <ws2tcpip.h>
 #endif
 
 /*
@@ -77,8 +79,6 @@
 #  if defined(_UNICODE) && !defined(UNICODE)
 #    error "_UNICODE is defined but UNICODE is not defined"
 #  endif
-#  include <winsock2.h>
-#  include <ws2tcpip.h>
 #  include <windows.h>
 #  include <winerror.h>
 #  include <tchar.h>
index 943ae6ad62f6c16b09039714e147c6d0b6f5cb2a..40a3f2ce661265164c895c6a21c4c770be65c28f 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -58,7 +58,7 @@
 #error "We cannot compile without socket() support!"
 #endif
 
-#if defined(HAVE_IF_NAMETOINDEX) && defined(_WIN32)
+#if defined(HAVE_IF_NAMETOINDEX) && defined(USE_WINSOCK)
 #if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR <= 5)
 #include <wincrypt.h>  /* workaround for old mingw-w64 missing to include it */
 #endif
index 5cc885137f4e267b6b7ee3b96dbc7e7bf520f276..27593c6636e45d056643671848458335aceaaa39 100644 (file)
@@ -693,6 +693,7 @@ static void init_terminal(void)
   }
 }
 
+#ifdef USE_WINSOCK
 /* The following STDIN non - blocking read techniques are heavily inspired
    by nmap and ncat (https://nmap.org/ncat/) */
 struct win_thread_data {
@@ -895,6 +896,7 @@ curl_socket_t win32_stdin_read_thread(void)
   assert(socket_r != CURL_SOCKET_BAD);
   return socket_r;
 }
+#endif /* USE_WINSOCK */
 
 #endif /* !CURL_WINDOWS_UWP */
 
index 0998303774893b22c0fd0f7a58a839d1153cc92d..300826ef26bb4b65b1c3fb22b21757d3f0e6af6f 100644 (file)
@@ -1119,7 +1119,7 @@ static void check_stdin_upload(struct OperationConfig *config,
 
   CURLX_SET_BINMODE(stdin);
   if(!strcmp(per->uploadfile, ".")) {
-#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
+#if defined(USE_WINSOCK) && !defined(CURL_WINDOWS_UWP)
     /* non-blocking stdin behavior on Windows is challenging
        Spawn a new thread that will read from stdin and write
        out to a socket */