From eb236329c469ec906a9c8be65e8128b1abd6d414 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 1 Apr 2023 12:31:16 +0000 Subject: [PATCH] delete redundant `HAVE_WINSOCK2_H` `libssh2.h` required `winsock2.h` for `_WIN32` since 81d53de4dc5ee39bd6215958c7dce3b12731195e (2011-06-04). Apply that to the whole codebase. This makes it unnecessary to detect `HAVE_WINSOCK2_H` and allows to drop all its uses. Completes TODO from b66d7317ca6c882afbe52fe426f68c119c40d348 TODO: Straighten out the use a mixture of `HAVE_WINDOWS_H`, `WIN32`, `_WIN32` to detect Windows. --- CMakeLists.txt | 1 - acinclude.m4 | 6 ------ configure.ac | 4 ++-- example/scp.c | 7 ++----- example/scp_nonblock.c | 7 ++----- example/scp_write.c | 2 +- example/scp_write_nonblock.c | 2 +- example/sftp.c | 7 ++----- example/sftp_RW_nonblock.c | 7 ++----- example/sftp_append.c | 2 +- example/sftp_mkdir.c | 2 +- example/sftp_mkdir_nonblock.c | 2 +- example/sftp_nonblock.c | 7 ++----- example/sftp_write.c | 2 +- example/sftp_write_nonblock.c | 2 +- example/sftp_write_sliding.c | 2 +- example/sftpdir.c | 2 +- example/sftpdir_nonblock.c | 2 +- example/ssh2.c | 2 -- example/ssh2_agent.c | 2 -- example/ssh2_agent_forwarding.c | 2 +- example/ssh2_echo.c | 2 +- example/ssh2_exec.c | 2 +- os400/libssh2_config.h | 3 --- src/libssh2_config_cmake.h.in | 1 - src/libssh2_priv.h | 2 -- tests/openssh_fixture.c | 4 ++-- tests/session_fixture.c | 5 ++--- tests/ssh2.c | 2 -- win32/libssh2_config.h | 1 - 30 files changed, 29 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e736cef..19dbfaa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,6 @@ check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files(sys/un.h HAVE_SYS_UN_H) -check_include_files(winsock2.h HAVE_WINSOCK2_H) # for example and tests check_include_files(sys/param.h HAVE_SYS_PARAM_H) diff --git a/acinclude.m4 b/acinclude.m4 index 8a09e257..130ac8bb 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -218,13 +218,7 @@ dnl the code was bad, try a different program now, test 3 #define WIN32_LEAN_AND_MEAN #endif #include -#ifdef HAVE_WINSOCK2_H #include -#else -#ifdef HAVE_WINSOCK_H -#include -#endif -#endif #endif ],[ /* ioctlsocket source code */ diff --git a/configure.ac b/configure.ac index 6c51288f..076eee6f 100644 --- a/configure.ac +++ b/configure.ac @@ -289,7 +289,7 @@ case $host in # These are POSIX-like systems using BSD-like sockets API. ;; *) - AC_CHECK_HEADERS([windows.h winsock2.h]) + AC_CHECK_HEADERS([windows.h]) ;; esac @@ -317,7 +317,7 @@ dnl Check for select() into ws2_32 for Msys/Mingw if test "$ac_cv_func_select" != "yes"; then AC_MSG_CHECKING([for select in ws2_32]) AC_TRY_LINK([ -#ifdef HAVE_WINSOCK2_H +#ifdef HAVE_WINDOWS_H #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif diff --git a/example/scp.c b/example/scp.c index 6b2788ee..f02944f9 100644 --- a/example/scp.c +++ b/example/scp.c @@ -11,8 +11,9 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -36,10 +37,6 @@ #include #include -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - int main(int argc, char *argv[]) { uint32_t hostaddr; diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 0b4a8ec8..0858b843 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -16,8 +16,9 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -44,10 +45,6 @@ #include #include -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/scp_write.c b/example/scp_write.c index 1f85a185..833b6018 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -11,7 +11,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index f41e44fd..f469abab 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -11,7 +11,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp.c b/example/sftp.c index d1100777..96fdea70 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -17,8 +17,9 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -46,10 +47,6 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - const char *keyfile1 = "~/.ssh/id_rsa.pub"; const char *keyfile2 = "~/.ssh/id_rsa"; const char *username = "username"; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 1830ec33..76dc525e 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -11,8 +11,9 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -43,10 +44,6 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - #define STORAGE "/tmp/sftp-storage" /* this is the local file name this example uses to store the downloaded file in */ diff --git a/example/sftp_append.c b/example/sftp_append.c index 37e22126..012af2f2 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 2888d3ed..9c9dc526 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index cba29daf..a24a1745 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 279cc8e4..5932ad05 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -17,8 +17,9 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include +# define write(f, b, c) write((f), (b), (unsigned int)(c)) #endif #ifdef HAVE_SYS_SOCKET_H # include @@ -49,10 +50,6 @@ #pragma warning(disable:4127) #endif -#ifdef WIN32 -#define write(f, b, c) write((f), (b), (unsigned int)(c)) -#endif - #ifdef HAVE_GETTIMEOFDAY /* diff in ms */ static long tvdiff(struct timeval newer, struct timeval older) diff --git a/example/sftp_write.c b/example/sftp_write.c index 804b69bd..5c6e5a80 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 35997c0e..584aab55 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index e87cbe86..a842271f 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftpdir.c b/example/sftpdir.c index 6f5079ff..e137a8a6 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 9228766b..fb229b99 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -17,7 +17,7 @@ #include #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2.c b/example/ssh2.c index f689c39d..7d87b2b9 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -23,8 +23,6 @@ #ifdef WIN32 # include -#endif -#ifdef HAVE_WINSOCK2_H # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 1eeaff14..33d41be4 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -18,8 +18,6 @@ #ifdef WIN32 # include -#endif -#ifdef HAVE_WINSOCK2_H # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 96b26288..3546d042 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -22,7 +22,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index ac202f2a..ae62a7cc 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -17,7 +17,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index c205f1a8..fb250e63 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -19,7 +19,7 @@ #include "libssh2_config.h" #include -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/os400/libssh2_config.h b/os400/libssh2_config.h index df3c381d..ac14da6a 100644 --- a/os400/libssh2_config.h +++ b/os400/libssh2_config.h @@ -134,9 +134,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 -/* Define to 1 if you have the header file. */ -#undef HAVE_WINSOCK2_H - /* to make a symbol visible */ #undef LIBSSH2_API diff --git a/src/libssh2_config_cmake.h.in b/src/libssh2_config_cmake.h.in index e0ccdade..0be020e1 100644 --- a/src/libssh2_config_cmake.h.in +++ b/src/libssh2_config_cmake.h.in @@ -45,7 +45,6 @@ #cmakedefine HAVE_SYS_IOCTL_H #cmakedefine HAVE_SYS_TIME_H #cmakedefine HAVE_SYS_UN_H -#cmakedefine HAVE_WINSOCK2_H /* for example and tests */ #cmakedefine HAVE_SYS_PARAM_H diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 87c7d4db..3fc63667 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -76,9 +76,7 @@ # define LIBSSH2_WINDOWS_APP # endif # endif -#endif /* WIN32 */ -#ifdef HAVE_WINSOCK2_H #include #include /* Force parameter type. */ diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index 1b169ff1..a34e4b9b 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -45,7 +45,7 @@ #include "openssh_fixture.h" #include "libssh2_config.h" -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 #include #endif #ifdef HAVE_SYS_SOCKET_H @@ -429,7 +429,7 @@ static char *running_container_id = NULL; int start_openssh_fixture(void) { int ret; -#ifdef HAVE_WINSOCK2_H +#ifdef WIN32 WSADATA wsadata; ret = WSAStartup(MAKEWORD(2, 0), &wsadata); diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 1a25feb1..7087c359 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -47,15 +47,14 @@ #ifdef WIN32 #include +#include #ifdef _MSC_VER #include #define getcwd _getcwd #define chdir _chdir #endif #endif -#ifdef HAVE_WINSOCK2_H -#include -#endif + #ifdef HAVE_SYS_SOCKET_H #include #endif diff --git a/tests/ssh2.c b/tests/ssh2.c index d9f1639e..b338c922 100644 --- a/tests/ssh2.c +++ b/tests/ssh2.c @@ -6,8 +6,6 @@ #ifdef WIN32 # include -#endif -#ifdef HAVE_WINSOCK2_H # include #endif #ifdef HAVE_SYS_SOCKET_H diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 493826c4..bc2ab681 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -10,7 +10,6 @@ #endif #define HAVE_LIBCRYPT32 -#define HAVE_WINSOCK2_H #define HAVE_STDLIB_H #define HAVE_IOCTLSOCKET #define HAVE_SELECT