From c1bc090d65b8d7d14e811dd36f5e8674be43dff3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 9 Dec 2023 20:37:11 +0000 Subject: [PATCH] windows: simplify detecting and using system headers - autotools, cmake: assume that if we detect Windows, `windows.h`, `winsock2.h` and `ws2tcpip.h` do exist. - lib: fix 3 outlier `#if` conditions to use `USE_WINSOCK` instead of looking for `winsock2.h`. - autotools: merge 3 Windows check methods into one. - move Watt-32 and lwIP socket support to `setup-win32.h` from `config-win32.h`. It opens up using these with all build tools. Also merge logic with Windows Sockets. - fix to assume Windows sockets with the mingw32ce toolchain. Follow-up to: 2748c64d605b19fb419ae56810ad8da36487a2d4 - cmake: delete unused variable `signature_call_conv` since eb33ccd5332435fa50f1758e5debb869c6942b7f. - autotools: simplify `CURL_CHECK_WIN32_LARGEFILE` detection. - examples/externalsocket: fix header order. - cmake/OtherTests.cmake: delete Windows-specific `_source_epilogue` that wasn't used anymore. - cmake/OtherTests.cmake: set `WIN32_LEAN_AND_MEAN` for test `SIZEOF_STRUCT_SOCKADDR_STORAGE`. After this patch curl universally uses `_WIN32` to guard Windows-specific logic. It guards Windows Sockets-specific logic with `USE_WINSOCK` (this might need further work). Reviewed-by: Jay Satiro Closes #12495 --- CMake/CurlTests.c | 30 ++--- CMake/OtherTests.cmake | 23 ++-- CMakeLists.txt | 13 +-- acinclude.m4 | 208 ++++++--------------------------- configure.ac | 38 ++---- docs/examples/externalsocket.c | 2 +- lib/cf-socket.c | 4 +- lib/config-win32.h | 55 --------- lib/config-win32ce.h | 9 -- lib/curl_config.h.cmake | 9 -- lib/curl_setup.h | 7 +- lib/inet_pton.h | 2 +- lib/setup-win32.h | 62 ++++++---- m4/curl-compilers.m4 | 3 +- m4/curl-functions.m4 | 29 ++--- 15 files changed, 125 insertions(+), 369 deletions(-) diff --git a/CMake/CurlTests.c b/CMake/CurlTests.c index e546286264..e00acc542e 100644 --- a/CMake/CurlTests.c +++ b/CMake/CurlTests.c @@ -164,13 +164,11 @@ int main(void) { ; return 0; } #ifdef HAVE_IOCTLSOCKET /* includes start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef HAVE_WINSOCK2_H -# include -# endif +# include # include #endif int main(void) @@ -186,13 +184,11 @@ int main(void) #ifdef HAVE_IOCTLSOCKET_CAMEL /* includes start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef HAVE_WINSOCK2_H -# include -# endif +# include # include #endif int main(void) @@ -207,13 +203,11 @@ int main(void) #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO /* includes start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef HAVE_WINSOCK2_H -# include -# endif +# include # include #endif int main(void) @@ -229,13 +223,11 @@ int main(void) #ifdef HAVE_IOCTLSOCKET_FIONBIO /* includes start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef HAVE_WINSOCK2_H -# include -# endif +# include # include #endif int main(void) @@ -307,13 +299,11 @@ int main(void) #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK /* includes start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef HAVE_WINSOCK2_H -# include -# endif +# include # include #endif /* includes start */ diff --git a/CMake/OtherTests.cmake b/CMake/OtherTests.cmake index a613f6ecdc..f769b95477 100644 --- a/CMake/OtherTests.cmake +++ b/CMake/OtherTests.cmake @@ -29,20 +29,15 @@ set(_source_epilogue "#undef inline") macro(add_header_include check header) if(${check}) - set(_source_epilogue "${_source_epilogue}\n#include <${header}>") + set(_source_epilogue "${_source_epilogue} + #include <${header}>") endif() endmacro() -set(signature_call_conv) -if(HAVE_WINDOWS_H) - set(_source_epilogue - "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif") - add_header_include(HAVE_WINSOCK2_H "winsock2.h") - add_header_include(HAVE_WINDOWS_H "windows.h") - set(signature_call_conv "PASCAL") - if(WIN32) - set(CMAKE_REQUIRED_LIBRARIES "ws2_32") - endif() +if(WIN32) + set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h") + set(CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN") + set(CMAKE_REQUIRED_LIBRARIES "ws2_32") else() add_header_include(HAVE_SYS_TYPES_H "sys/types.h") add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h") @@ -57,7 +52,7 @@ check_c_source_compiles("${_source_epilogue} return 0; }" HAVE_MSG_NOSIGNAL) -if(NOT HAVE_WINDOWS_H) +if(NOT WIN32) add_header_include(HAVE_SYS_TIME_H "sys/time.h") endif() check_c_source_compiles("${_source_epilogue} @@ -70,9 +65,7 @@ int main(void) { return 0; }" HAVE_STRUCT_TIMEVAL) -if(HAVE_WINDOWS_H) - set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h") -else() +if(NOT WIN32) set(CMAKE_EXTRA_INCLUDE_FILES) if(HAVE_SYS_SOCKET_H) set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h") diff --git a/CMakeLists.txt b/CMakeLists.txt index d5f250da01..9f284bd9f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,9 +351,6 @@ include(CheckCSourceCompiles) # On windows preload settings if(WIN32) - set(HAVE_WINDOWS_H 1) - set(HAVE_WS2TCPIP_H 1) - set(HAVE_WINSOCK2_H 1) include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake) endif() @@ -770,7 +767,7 @@ if(NOT CURL_DISABLE_LDAP) endif() set(NEED_LBER_H ON) set(_HEADER_LIST) - if(HAVE_WINDOWS_H) + if(WIN32) list(APPEND _HEADER_LIST "windows.h") endif() if(HAVE_SYS_TYPES_H) @@ -1053,9 +1050,9 @@ endif() # Check for header files if(WIN32) - check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H) - check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H) - check_include_file_concat("windows.h" HAVE_WINDOWS_H) + set(CURL_INCLUDES ${CURL_INCLUDES} "winsock2.h") + set(CURL_INCLUDES ${CURL_INCLUDES} "ws2tcpip.h") + set(CURL_INCLUDES ${CURL_INCLUDES} "windows.h") endif() if(WIN32) @@ -1391,7 +1388,7 @@ endif() # TODO test which of these headers are required if(WIN32) - set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H}) + set(CURL_PULL_WS2TCPIP_H 1) else() set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H}) set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H}) diff --git a/acinclude.m4 b/acinclude.m4 index ac026e39d2..df80d693a5 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -171,159 +171,43 @@ AC_DEFUN([CURL_CHECK_AIX_ALL_SOURCE], [ ]) -dnl CURL_CHECK_HEADER_WINDOWS -dnl ------------------------------------------------- -dnl Check for compilable and valid windows.h header - -AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [ - AC_CACHE_CHECK([for windows.h], [curl_cv_header_windows_h], [ - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([[ -#undef inline -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include - ]],[[ -#if defined(__CYGWIN__) || defined(__CEGCC__) - HAVE_WINDOWS_H shall not be defined. -#else - int dummy=2*WINVER; -#endif - ]]) - ],[ - curl_cv_header_windows_h="yes" - ],[ - curl_cv_header_windows_h="no" - ]) - ]) - case "$curl_cv_header_windows_h" in - yes) - AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1, - [Define to 1 if you have the windows.h header file.]) - ;; - esac -]) - - dnl CURL_CHECK_NATIVE_WINDOWS dnl ------------------------------------------------- dnl Check if building a native Windows target AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl AC_CACHE_CHECK([whether build target is a native Windows one], [curl_cv_native_windows], [ - if test "$curl_cv_header_windows_h" = "no"; then - curl_cv_native_windows="no" - else - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([[ - ]],[[ -#if defined(__MINGW32__) || defined(__MINGW32CE__) || \ - (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64))) - int dummy=1; + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ + ]],[[ +#ifdef _WIN32 + int dummy=1; #else - Not a native Windows build target. + Not a native Windows build target. #endif - ]]) - ],[ - curl_cv_native_windows="yes" - ],[ - curl_cv_native_windows="no" - ]) - fi + ]]) + ],[ + curl_cv_native_windows="yes" + ],[ + curl_cv_native_windows="no" + ]) ]) AM_CONDITIONAL(DOING_NATIVE_WINDOWS, test "x$curl_cv_native_windows" = xyes) ]) -dnl CURL_CHECK_HEADER_WINSOCK2 -dnl ------------------------------------------------- -dnl Check for compilable and valid winsock2.h header - -AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl - AC_CACHE_CHECK([for winsock2.h], [curl_cv_header_winsock2_h], [ - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([[ -#undef inline -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#include - ]],[[ -#if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__) - HAVE_WINSOCK2_H shall not be defined. -#else - int dummy=2*IPPROTO_ESP; -#endif - ]]) - ],[ - curl_cv_header_winsock2_h="yes" - ],[ - curl_cv_header_winsock2_h="no" - ]) - ]) - case "$curl_cv_header_winsock2_h" in - yes) - AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1, - [Define to 1 if you have the winsock2.h header file.]) - ;; - esac -]) - - -dnl CURL_CHECK_HEADER_WS2TCPIP -dnl ------------------------------------------------- -dnl Check for compilable and valid ws2tcpip.h header - -AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl - AC_CACHE_CHECK([for ws2tcpip.h], [curl_cv_header_ws2tcpip_h], [ - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([[ -#undef inline -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#include -#include - ]],[[ -#if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__) - HAVE_WS2TCPIP_H shall not be defined. -#else - int dummy=2*IP_PKTINFO; -#endif - ]]) - ],[ - curl_cv_header_ws2tcpip_h="yes" - ],[ - curl_cv_header_ws2tcpip_h="no" - ]) - ]) - case "$curl_cv_header_ws2tcpip_h" in - yes) - AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1, - [Define to 1 if you have the ws2tcpip.h header file.]) - ;; - esac -]) - - dnl CURL_CHECK_HEADER_LBER dnl ------------------------------------------------- dnl Check for compilable and valid lber.h header, dnl and check if it is needed even with ldap.h AC_DEFUN([CURL_CHECK_HEADER_LBER], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl + AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl AC_CACHE_CHECK([for lber.h], [curl_cv_header_lber_h], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -355,7 +239,7 @@ AC_DEFUN([CURL_CHECK_HEADER_LBER], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -403,7 +287,7 @@ AC_DEFUN([CURL_CHECK_HEADER_LDAP], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -449,7 +333,7 @@ AC_DEFUN([CURL_CHECK_HEADER_LDAP_SSL], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -534,7 +418,7 @@ AC_DEFUN([CURL_CHECK_LIBS_WINLDAP], [ AC_LINK_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -632,7 +516,7 @@ AC_DEFUN([CURL_CHECK_LIBS_LDAP], [ AC_LINK_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -701,13 +585,11 @@ AC_DEFUN([TYPE_SOCKADDR_STORAGE], [if struct sockaddr_storage is defined]), , [ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #else #ifdef HAVE_SYS_TYPES_H @@ -731,7 +613,7 @@ dnl ------------------------------------------------- dnl Test if the socket recv() function is available, AC_DEFUN([CURL_CHECK_FUNC_RECV], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl + AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl AC_CHECK_HEADERS(sys/types.h sys/socket.h) # @@ -739,13 +621,11 @@ AC_DEFUN([CURL_CHECK_FUNC_RECV], [ AC_LINK_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #else $curl_includes_bsdsocket @@ -782,7 +662,7 @@ dnl ------------------------------------------------- dnl Test if the socket send() function is available, AC_DEFUN([CURL_CHECK_FUNC_SEND], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl + AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl AC_CHECK_HEADERS(sys/types.h sys/socket.h) # @@ -790,13 +670,11 @@ AC_DEFUN([CURL_CHECK_FUNC_SEND], [ AC_LINK_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #else $curl_includes_bsdsocket @@ -837,13 +715,11 @@ AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #else #ifdef HAVE_SYS_TYPES_H @@ -876,19 +752,17 @@ dnl ------------------------------------------------- dnl Check for timeval struct AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl + AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl AC_CHECK_HEADERS(sys/types.h sys/time.h sys/socket.h) AC_CACHE_CHECK([for struct timeval], [curl_cv_struct_timeval], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #endif #ifdef HAVE_SYS_TYPES_H @@ -937,13 +811,11 @@ AC_DEFUN([TYPE_IN_ADDR_T], [ AC_LINK_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #else #ifdef HAVE_SYS_TYPES_H @@ -979,13 +851,11 @@ AC_DEFUN([TYPE_IN_ADDR_T], [ esac ],[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #else #ifdef HAVE_SYS_TYPES_H @@ -1197,7 +1067,7 @@ AC_DEFUN([CURL_CHECK_LIBS_CONNECT], [ AC_LANG_PROGRAM([[ $curl_includes_winsock2 $curl_includes_bsdsocket - #if !defined(HAVE_WINDOWS_H) && !defined(HAVE_PROTO_BSDSOCKET_H) + #if !defined(_WIN32) && !defined(HAVE_PROTO_BSDSOCKET_H) int connect(int, void*, int); #endif ]],[[ @@ -1294,13 +1164,11 @@ AC_DEFUN([CURL_CHECK_FUNC_SELECT], [ AC_LINK_IFELSE([ AC_LANG_PROGRAM([[ #undef inline -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #endif #ifdef HAVE_SYS_TYPES_H @@ -1310,7 +1178,7 @@ AC_DEFUN([CURL_CHECK_FUNC_SELECT], [ #include #endif #include -#ifndef HAVE_WINDOWS_H +#ifndef _WIN32 #ifdef HAVE_SYS_SELECT_H #include #elif defined(HAVE_UNISTD_H) @@ -1547,17 +1415,15 @@ dnl ------------------------------------------------- dnl Check if curl's WIN32 large file will be used AC_DEFUN([CURL_CHECK_WIN32_LARGEFILE], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl + AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl AC_MSG_CHECKING([whether build target supports WIN32 file API]) curl_win32_file_api="no" - if test "$curl_cv_header_windows_h" = "yes"; then + if test "$curl_cv_native_windows" = "yes"; then if test x"$enable_largefile" != "xno"; then AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ ]],[[ -#if !defined(_WIN32_WCE) && \ - (defined(__MINGW32__) || \ - (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)))) +#if !defined(_WIN32_WCE) && (defined(__MINGW32__) || defined(_MSC_VER)) int dummy=1; #else WIN32 large file API not supported. @@ -1606,10 +1472,10 @@ dnl ------------------------------------------------- dnl Check if curl's WIN32 crypto lib can be used AC_DEFUN([CURL_CHECK_WIN32_CRYPTO], [ - AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl + AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl AC_MSG_CHECKING([whether build target supports WIN32 crypto API]) curl_win32_crypto_api="no" - if test "$curl_cv_header_windows_h" = "yes"; then + if test "$curl_cv_native_windows" = "yes"; then AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #undef inline diff --git a/configure.ac b/configure.ac index c4e026068e..810e3562bd 100644 --- a/configure.ac +++ b/configure.ac @@ -503,6 +503,7 @@ dnl platform/compiler/architecture specific checks/flags dnl ********************************************************************** CURL_CHECK_COMPILER +CURL_CHECK_NATIVE_WINDOWS CURL_SET_COMPILER_BASIC_OPTS CURL_SET_COMPILER_DEBUG_OPTS CURL_SET_COMPILER_OPTIMIZE_OPTS @@ -583,25 +584,6 @@ dnl ********************************************************************** dnl Compilation based checks should not be done before this point. dnl ********************************************************************** -dnl ********************************************************************** -dnl Make sure that our checks for headers windows.h winsock2.h -dnl and ws2tcpip.h take precedence over any other further checks which -dnl could be done later using AC_CHECK_HEADER or AC_CHECK_HEADERS for -dnl this specific header files. And do them before its results are used. -dnl ********************************************************************** - -CURL_CHECK_HEADER_WINDOWS -CURL_CHECK_NATIVE_WINDOWS -case X-"$curl_cv_native_windows" in - X-yes) - CURL_CHECK_HEADER_WINSOCK2 - CURL_CHECK_HEADER_WS2TCPIP - ;; - *) - curl_cv_header_winsock2_h="no" - curl_cv_header_ws2tcpip_h="no" - ;; -esac CURL_CHECK_WIN32_LARGEFILE CURL_CHECK_WIN32_CRYPTO @@ -1130,23 +1112,19 @@ fi if test "$HAVE_GETHOSTBYNAME" != "1" then dnl This is for winsock systems - if test "$curl_cv_header_windows_h" = "yes"; then - if test "$curl_cv_header_winsock2_h" = "yes"; then - winsock_LIB="-lws2_32" - fi + if test "$curl_cv_native_windows" = "yes"; then + winsock_LIB="-lws2_32" if test ! -z "$winsock_LIB"; then my_ac_save_LIBS=$LIBS LIBS="$winsock_LIB $LIBS" AC_MSG_CHECKING([for gethostbyname in $winsock_LIB]) AC_LINK_IFELSE([ AC_LANG_PROGRAM([[ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include -#endif #include #endif ]],[[ @@ -1668,7 +1646,7 @@ AS_HELP_STRING([--disable-ipv6],[Disable IPv6 support]), AC_RUN_IFELSE([AC_LANG_SOURCE([[ /* are AF_INET6 and sockaddr_in6 available? */ #include -#ifdef HAVE_WINSOCK2_H +#ifdef _WIN32 #include #include #else @@ -1707,7 +1685,7 @@ if test "$ipv6" = yes; then AC_MSG_CHECKING([if struct sockaddr_in6 has sin6_scope_id member]) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([[ #include -#ifdef HAVE_WINSOCK2_H +#ifdef _WIN32 #include #include #else @@ -3473,14 +3451,12 @@ AC_CHECK_TYPE(sa_family_t, AC_DEFINE(CURL_SA_FAMILY_T, ADDRESS_FAMILY, [IP address type in sockaddr]), AC_DEFINE(CURL_SA_FAMILY_T, unsigned short, [IP address type in sockaddr]), [ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#ifdef HAVE_WINSOCK2_H #include #endif -#endif #ifdef HAVE_SYS_SOCKET_H #include #endif diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 270a31996c..6c9540a6db 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -31,9 +31,9 @@ #include #ifdef _WIN32 -#include #include #include +#include #define close closesocket #else #include /* socket types */ diff --git a/lib/cf-socket.c b/lib/cf-socket.c index e868b6bbfa..bd4f0d1e97 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -137,14 +137,14 @@ static void nosigpipe(struct Curl_easy *data, #define nosigpipe(x,y) Curl_nop_stmt #endif -#if defined(__DragonFly__) || defined(HAVE_WINSOCK2_H) +#if defined(__DragonFly__) || defined(USE_WINSOCK) /* DragonFlyBSD and Windows use millisecond units */ #define KEEPALIVE_FACTOR(x) (x *= 1000) #else #define KEEPALIVE_FACTOR(x) #endif -#if defined(HAVE_WINSOCK2_H) && !defined(SIO_KEEPALIVE_VALS) +#if defined(USE_WINSOCK) && !defined(SIO_KEEPALIVE_VALS) #define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4) struct tcp_keepalive { diff --git a/lib/config-win32.h b/lib/config-win32.h index 7b8a289bcd..89ed1a0f16 100644 --- a/lib/config-win32.h +++ b/lib/config-win32.h @@ -97,15 +97,6 @@ #define HAVE_UNISTD_H 1 #endif -/* Define if you have the header file. */ -#define HAVE_WINDOWS_H 1 - -/* Define if you have the header file. */ -#define HAVE_WINSOCK2_H 1 - -/* Define if you have the header file. */ -#define HAVE_WS2TCPIP_H 1 - /* Define to 1 if you have the header file. */ #if defined(__MINGW32__) #define HAVE_LIBGEN_H 1 @@ -292,52 +283,6 @@ /* Define to the size of `curl_off_t', as computed by sizeof. */ #define SIZEOF_CURL_OFF_T 8 -/* ---------------------------------------------------------------- */ -/* BSD-style lwIP TCP/IP stack SPECIFIC */ -/* ---------------------------------------------------------------- */ - -/* Define to use BSD-style lwIP TCP/IP stack. */ -/* #define USE_LWIPSOCK 1 */ - -#ifdef USE_LWIPSOCK -# undef USE_WINSOCK -# undef HAVE_WINSOCK2_H -# undef HAVE_WS2TCPIP_H -# 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 -# define LWIP_POSIX_SOCKETS_IO_NAMES 0 -# define RECV_TYPE_ARG1 int -# define RECV_TYPE_ARG3 size_t -# define SEND_TYPE_ARG1 int -# define SEND_TYPE_ARG3 size_t -#endif - -/* ---------------------------------------------------------------- */ -/* Watt-32 tcp/ip SPECIFIC */ -/* ---------------------------------------------------------------- */ - -#ifdef USE_WATT32 - #include - #undef byte - #undef word - #undef USE_WINSOCK - #undef HAVE_WINSOCK2_H - #undef HAVE_WS2TCPIP_H - #define HAVE_SYS_IOCTL_H - #define HAVE_SYS_SOCKET_H - #define HAVE_NETINET_IN_H - #define HAVE_NETDB_H - #define HAVE_ARPA_INET_H - #define SOCKET int -#endif - - /* ---------------------------------------------------------------- */ /* COMPILER SPECIFIC */ /* ---------------------------------------------------------------- */ diff --git a/lib/config-win32ce.h b/lib/config-win32ce.h index e0db57fd0f..ae3ca290c3 100644 --- a/lib/config-win32ce.h +++ b/lib/config-win32ce.h @@ -85,15 +85,6 @@ #define HAVE_UNISTD_H 1 #endif -/* Define if you have the header file. */ -#define HAVE_WINDOWS_H 1 - -/* Define if you have the header file. */ -#define HAVE_WINSOCK2_H 1 - -/* Define if you have the header file. */ -#define HAVE_WS2TCPIP_H 1 - /* ---------------------------------------------------------------- */ /* OTHER HEADER INFO */ /* ---------------------------------------------------------------- */ diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index 339358ea36..8c824721aa 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -599,18 +599,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UTIME_H 1 -/* Define to 1 if you have the windows.h header file. */ -#cmakedefine HAVE_WINDOWS_H 1 - -/* Define to 1 if you have the winsock2.h header file. */ -#cmakedefine HAVE_WINSOCK2_H 1 - /* Define this symbol if your OS supports changing the contents of argv */ #cmakedefine HAVE_WRITABLE_ARGV 1 -/* Define to 1 if you have the ws2tcpip.h header file. */ -#cmakedefine HAVE_WS2TCPIP_H 1 - /* Define to 1 if you need the lber.h header file even with ldap.h */ #cmakedefine NEED_LBER_H 1 diff --git a/lib/curl_setup.h b/lib/curl_setup.h index f81cf61002..fd7358b450 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -253,7 +253,7 @@ * Windows setup file includes some system headers. */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # include "setup-win32.h" #endif @@ -725,10 +725,7 @@ */ #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H) -# if defined(SOCKET) || \ - defined(USE_WINSOCK) || \ - defined(HAVE_WINSOCK2_H) || \ - defined(HAVE_WS2TCPIP_H) +# if defined(SOCKET) || defined(USE_WINSOCK) # error "WinSock and lwIP TCP/IP stack definitions shall not coexist!" # endif #endif diff --git a/lib/inet_pton.h b/lib/inet_pton.h index 82fde7e2eb..a6d161a999 100644 --- a/lib/inet_pton.h +++ b/lib/inet_pton.h @@ -31,7 +31,7 @@ int Curl_inet_pton(int, const char *, void *); #ifdef HAVE_INET_PTON #ifdef HAVE_ARPA_INET_H #include -#elif defined(HAVE_WS2TCPIP_H) +#elif defined(USE_WINSOCK) /* inet_pton() exists in Vista or later */ #include #endif diff --git a/lib/setup-win32.h b/lib/setup-win32.h index 4e034d4bb2..d7e2e6be11 100644 --- a/lib/setup-win32.h +++ b/lib/setup-win32.h @@ -24,18 +24,53 @@ * ***************************************************************************/ +#undef USE_WINSOCK +/* ---------------------------------------------------------------- */ +/* Watt-32 TCP/IP SPECIFIC */ +/* ---------------------------------------------------------------- */ +#ifdef USE_WATT32 +# include +# undef byte +# undef word +# define HAVE_SYS_IOCTL_H +# define HAVE_SYS_SOCKET_H +# define HAVE_NETINET_IN_H +# define HAVE_NETDB_H +# define HAVE_ARPA_INET_H +# define SOCKET int +/* ---------------------------------------------------------------- */ +/* BSD-style lwIP TCP/IP stack SPECIFIC */ +/* ---------------------------------------------------------------- */ +#elif defined(USE_LWIPSOCK) + /* 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 +# define LWIP_POSIX_SOCKETS_IO_NAMES 0 +# define RECV_TYPE_ARG1 int +# define RECV_TYPE_ARG3 size_t +# define SEND_TYPE_ARG1 int +# define SEND_TYPE_ARG3 size_t +#elif defined(_WIN32) +# define USE_WINSOCK 2 +#endif + /* * Include header files for windows builds before redefining anything. * Use this preprocessor block only to include or exclude windows.h, * winsock2.h or ws2tcpip.h. Any other windows thing belongs * to any other further and independent block. Under Cygwin things work * just as under linux (e.g. ) and the winsock headers should - * never be included when __CYGWIN__ is defined. configure script takes - * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK2_H, - * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined. + * never be included when __CYGWIN__ is defined. */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # if defined(UNICODE) && !defined(_UNICODE) # error "UNICODE is defined but _UNICODE is not defined" # endif @@ -53,12 +88,8 @@ # ifndef NOGDI # define NOGDI # endif -# ifdef HAVE_WINSOCK2_H -# include -# ifdef HAVE_WS2TCPIP_H -# include -# endif -# endif +# include +# include # include # include # include @@ -67,17 +98,6 @@ # endif #endif -/* - * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else - * undefine USE_WINSOCK. - */ - -#undef USE_WINSOCK - -#ifdef HAVE_WINSOCK2_H -# define USE_WINSOCK 2 -#endif - /* * Define _WIN32_WINNT_[OS] symbols because not all Windows build systems have * those symbols to compare against, and even those that do may be missing diff --git a/m4/curl-compilers.m4 b/m4/curl-compilers.m4 index 5346321641..7968a113a9 100644 --- a/m4/curl-compilers.m4 +++ b/m4/curl-compilers.m4 @@ -194,7 +194,6 @@ AC_DEFUN([CURL_CHECK_COMPILER_GNU_C], [ flags_opt_all="-O -O0 -O1 -O2 -O3 -Os -Og -Ofast" flags_opt_yes="-O2" flags_opt_off="-O0" - CURL_CHECK_DEF([_WIN32], [], [silent]) else AC_MSG_RESULT([no]) fi @@ -1035,7 +1034,7 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [ dnl Only gcc 4.5 or later if test "$compiler_num" -ge "405"; then dnl Only windows targets - if test "$curl_cv_have_def__WIN32" = "yes"; then + if test "$curl_cv_native_windows" = "yes"; then tmp_CFLAGS="$tmp_CFLAGS -Wno-pedantic-ms-format" fi fi diff --git a/m4/curl-functions.m4 b/m4/curl-functions.m4 index a3275673a2..18147e4cac 100644 --- a/m4/curl-functions.m4 +++ b/m4/curl-functions.m4 @@ -46,7 +46,7 @@ curl_includes_arpa_inet="\ #ifdef HAVE_ARPA_INET_H # include #endif -#ifdef HAVE_WINSOCK2_H +#ifdef _WIN32 #include #include #endif @@ -414,18 +414,15 @@ dnl included when winsock2.h is to be included. AC_DEFUN([CURL_INCLUDES_WINSOCK2], [ curl_includes_winsock2="\ /* includes start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef HAVE_WINSOCK2_H -# include -# endif +# include # include #endif /* includes end */" - CURL_CHECK_HEADER_WINDOWS - CURL_CHECK_HEADER_WINSOCK2 + CURL_CHECK_NATIVE_WINDOWS ]) @@ -437,22 +434,16 @@ dnl included when ws2tcpip.h is to be included. AC_DEFUN([CURL_INCLUDES_WS2TCPIP], [ curl_includes_ws2tcpip="\ /* includes start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef HAVE_WINSOCK2_H -# include -# ifdef HAVE_WS2TCPIP_H -# include -# endif -# endif +# include +# include # include #endif /* includes end */" - CURL_CHECK_HEADER_WINDOWS - CURL_CHECK_HEADER_WINSOCK2 - CURL_CHECK_HEADER_WS2TCPIP + CURL_CHECK_NATIVE_WINDOWS ]) @@ -510,7 +501,7 @@ dnl defines function calling convention. AC_DEFUN([CURL_PREPROCESS_CALLCONV], [ curl_preprocess_callconv="\ /* preprocess start */ -#ifdef HAVE_WINDOWS_H +#ifdef _WIN32 # define FUNCALLCONV __stdcall #else # define FUNCALLCONV @@ -1794,7 +1785,7 @@ AC_DEFUN([CURL_CHECK_FUNC_GETADDRINFO], [ struct addrinfo *ai = 0; int error; - #ifdef HAVE_WINSOCK2_H + #ifdef _WIN32 WSADATA wsa; if(WSAStartup(MAKEWORD(2, 2), &wsa)) exit(2);