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
#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"
/* 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
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 *
/* 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
/*
# 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>
#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
}
}
+#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 {
assert(socket_r != CURL_SOCKET_BAD);
return socket_r;
}
+#endif /* USE_WINSOCK */
#endif /* !CURL_WINDOWS_UWP */
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 */