diff --git a/CMakeLists.txt b/CMakeLists.txt index f84d4b77..ec5f74fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ check_include_files(inttypes.h HAVE_INTTYPES_H) if(NOT MSVC) check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(sys/time.h HAVE_SYS_TIME_H) - check_include_files(sys/param.h HAVE_SYS_PARAM_H) + check_include_files(sys/param.h HAVE_SYS_PARAM_H) # tests endif() if(NOT WIN32) check_include_files(sys/select.h HAVE_SYS_SELECT_H) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 1d9b041a..46d21e90 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -10,9 +10,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -23,11 +20,9 @@ #include #endif -#include -#include -#include #include #include +#include #ifndef INADDR_NONE #define INADDR_NONE (in_addr_t)~0 diff --git a/example/scp.c b/example/scp.c index 2c0e0af6..a80c5124 100644 --- a/example/scp.c +++ b/example/scp.c @@ -22,11 +22,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 615b4ea5..13951dc6 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -17,9 +17,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -33,11 +30,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/scp_write.c b/example/scp_write.c index 7da38ac7..7390548d 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -18,11 +18,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 996778cb..29ff08bd 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -8,9 +8,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -21,12 +18,8 @@ #include #endif -#include -#include -#include #include -#include -#include +#include /* for time() */ static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp.c b/example/sftp.c index 3a3c5866..c85012bc 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -28,11 +28,8 @@ #include #endif -#include -#include -#include #include -#include +#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 61dda867..25f02a31 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -18,9 +18,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -28,11 +25,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_append.c b/example/sftp_append.c index 6793ccb7..60ced4f3 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 3937d5be..2edfcba2 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index acbec2b4..b9902372 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index b44574c4..19685aca 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -18,9 +18,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -34,11 +31,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_write.c b/example/sftp_write.c index b2169e40..85818a71 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index 602a780c..4570318d 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -14,9 +14,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -27,12 +24,8 @@ #include #endif -#include -#include -#include #include -#include -#include +#include /* for time() */ static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index b1b7972b..f6f2b33b 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -14,9 +14,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -27,12 +24,9 @@ #include #endif -#include -#include -#include #include -#include -#include +#include /* for time() */ +#include static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *privkey = "/home/username/.ssh/id_rsa"; diff --git a/example/sftpdir.c b/example/sftpdir.c index 655db525..8d9bd3d9 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -24,11 +24,8 @@ #include #endif -#include -#include -#include #include -#include +#include #if defined(_MSC_VER) #define __FILESIZE "I64u" diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 8237f6a7..ca12e625 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -24,11 +24,7 @@ #include #endif -#include -#include -#include #include -#include #if defined(_MSC_VER) #define __FILESIZE "I64u" diff --git a/example/ssh2.c b/example/ssh2.c index 6267244e..26f15cfe 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -28,12 +28,9 @@ #include #endif -#include -#include -#include #include #include -#include +#include #if defined(_MSC_VER) && _MSC_VER < 1900 #define snprintf _snprintf diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 6ad76313..9c7997d1 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -22,12 +22,8 @@ #include #endif -#include -#include -#include #include -#include -#include +#include static const char *username = "username"; diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 047920c9..c12c1989 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -17,9 +17,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -30,12 +27,8 @@ #include #endif -#include -#include -#include #include #include -#include static const char *hostname = "127.0.0.1"; static const char *commandline = "uptime"; diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index 1fa87b7a..70115fed 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -12,9 +12,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -25,12 +22,9 @@ #include #endif -#include -#include -#include #include #include -#include +#include static const char *hostname = "127.0.0.1"; static const char *commandline = "cat"; diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index d180f62d..c39421fc 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -14,9 +14,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -27,12 +24,9 @@ #include #endif -#include -#include -#include #include #include -#include +#include static const char *hostname = "127.0.0.1"; static const char *commandline = "uptime"; diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index fd24039f..7029fb8d 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -14,11 +14,7 @@ #include #endif -#include -#include -#include #include -#include #include #ifndef INADDR_NONE diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index a0b1cd69..156075bb 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -10,9 +10,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -23,11 +20,9 @@ #include #endif -#include -#include -#include #include #include +#include #ifndef INADDR_NONE #define INADDR_NONE (in_addr_t)~0 diff --git a/example/x11.c b/example/x11.c index 6254519f..fce07771 100644 --- a/example/x11.c +++ b/example/x11.c @@ -20,9 +20,6 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -33,11 +30,7 @@ #include #endif -#include -#include -#include #include -#include #include #include diff --git a/include/libssh2.h b/include/libssh2.h index 28698317..e13e2f13 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -185,8 +185,6 @@ typedef int libssh2_socket_t; #ifdef LIBSSH2_USE_WIN32_LARGE_FILES # include -# include -# include # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%I64d" typedef struct _stati64 libssh2_struct_stat; typedef __int64 libssh2_struct_stat_size; @@ -197,8 +195,6 @@ typedef __int64 libssh2_struct_stat_size; */ #ifdef LIBSSH2_USE_WIN32_SMALL_FILES -# include -# include # ifndef _WIN32_WCE # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%d" typedef struct _stat libssh2_struct_stat; diff --git a/src/agent.c b/src/agent.c index cb1fe20b..76308f7d 100644 --- a/src/agent.c +++ b/src/agent.c @@ -39,7 +39,10 @@ #include "libssh2_priv.h" #include "agent.h" + #include +#include /* for getenv() */ + #ifdef HAVE_SYS_UN_H #include #else @@ -48,6 +51,7 @@ support them. */ #undef PF_UNIX #endif + #include "userauth.h" #include "session.h" diff --git a/src/agent_win.c b/src/agent_win.c index 4a93e1ca..b735e102 100644 --- a/src/agent_win.c +++ b/src/agent_win.c @@ -39,7 +39,6 @@ #include "libssh2_priv.h" #include "agent.h" -#include #if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index 5382c0bd..91be901c 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -20,10 +20,6 @@ #ifndef HAVE_BCRYPT_PBKDF #include -#include -#ifdef HAVE_SYS_PARAM_H -#include -#endif #define LIBSSH2_BCRYPT_PBKDF_C #include "blowfish.c" diff --git a/src/channel.c b/src/channel.c index cf094298..06a6acae 100644 --- a/src/channel.c +++ b/src/channel.c @@ -39,13 +39,14 @@ */ #include "libssh2_priv.h" + #ifdef HAVE_UNISTD_H #include #endif -#include #ifdef HAVE_INTTYPES_H #include #endif + #include #include "channel.h" diff --git a/src/comp.c b/src/comp.c index 527c516a..f3565056 100644 --- a/src/comp.c +++ b/src/comp.c @@ -37,6 +37,7 @@ */ #include "libssh2_priv.h" + #ifdef LIBSSH2_HAVE_ZLIB #include #undef compress /* dodge name clash with ZLIB macro */ diff --git a/src/libgcrypt.c b/src/libgcrypt.c index ccee5834..55d971b6 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -38,8 +38,6 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ -#include - #if LIBSSH2_RSA int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 857b1359..82c3afe2 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -47,6 +47,7 @@ #include "libssh2_setup.h" #include +#include #include #include @@ -59,14 +60,8 @@ */ #ifdef HAVE_POLL # include -#else -# if defined(HAVE_SELECT) && !defined(WIN32) -# ifdef HAVE_SYS_SELECT_H -# include -# else -# include -# endif -# endif +#elif defined(HAVE_SELECT) && defined(HAVE_SYS_SELECT_H) +# include #endif /* Needed for struct iovec on some platforms */ @@ -914,14 +909,6 @@ struct _LIBSSH2_SESSION long packet_read_timeout; }; -#if defined(HAVE_STRTOLL) -#define scpsize_strtol strtoll -#elif defined(HAVE_STRTOI64) -#define scpsize_strtol _strtoi64 -#else -#define scpsize_strtol strtol -#endif - /* session.state bits */ #define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000001 #define LIBSSH2_STATE_NEWKEYS 0x00000002 diff --git a/src/mbedtls.c b/src/mbedtls.c index c7d0b56b..4a441cba 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -37,6 +37,8 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ +#include + #if MBEDTLS_VERSION_NUMBER < 0x03000000 #define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) #define mbedtls_cipher_info_get_iv_size(c) (c->iv_size) diff --git a/src/mbedtls.h b/src/mbedtls.h index 80658440..80a051ed 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -39,9 +39,6 @@ #define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls -#include -#include - #include #include #include @@ -162,6 +159,7 @@ #define libssh2_sha1(data, datalen, hash) \ _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA1, hash) + /*******************************************************************/ /* * mbedTLS backend: SHA256 functions diff --git a/src/misc.c b/src/misc.c index 8151eab7..10864b8b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -40,21 +40,18 @@ #include "libssh2_priv.h" #include "misc.h" -#include - #ifdef HAVE_UNISTD_H #include #endif +#include + #ifdef WIN32 /* Force parameter type. */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) #define send(s, b, l, f) send((s), (b), (int)(l), (f)) #endif -#include -#include - /* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible. We provide a safe wrapper if snprintf not found */ #ifdef LIBSSH2_SNPRINTF diff --git a/src/openssl.c b/src/openssl.c index 590b28cc..89560efc 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -40,8 +40,8 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ +#include #include -#include #ifndef EVP_MAX_BLOCK_LENGTH #define EVP_MAX_BLOCK_LENGTH 32 diff --git a/src/os400qc3.c b/src/os400qc3.c index 870b5100..ed7e8f6e 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -41,7 +41,6 @@ #include -#include #include #include #include diff --git a/src/packet.c b/src/packet.c index 9023f3bf..8c8e6675 100644 --- a/src/packet.c +++ b/src/packet.c @@ -39,24 +39,18 @@ */ #include "libssh2_priv.h" -#include -#include #ifdef HAVE_UNISTD_H #include #endif - #ifdef HAVE_INTTYPES_H #include #endif - /* Needed for struct iovec on some platforms */ #ifdef HAVE_SYS_UIO_H #include #endif -#include - #include "transport.h" #include "channel.h" #include "packet.h" diff --git a/src/scp.c b/src/scp.c index b68cb8e3..b829dad8 100644 --- a/src/scp.c +++ b/src/scp.c @@ -37,12 +37,19 @@ */ #include "libssh2_priv.h" -#include -#include #include "channel.h" #include "session.h" +#include /* strtoll(), _strtoi64(), strtol() */ + +#if defined(HAVE_STRTOLL) +#define scpsize_strtol strtoll +#elif defined(HAVE_STRTOI64) +#define scpsize_strtol _strtoi64 +#else +#define scpsize_strtol strtol +#endif /* Max. length of a quoted string after libssh2_shell_quotearg() processing */ #define _libssh2_shell_quotedsize(s) (3 * strlen(s) + 2) diff --git a/src/session.c b/src/session.c index 7b1f6828..a4d602ba 100644 --- a/src/session.c +++ b/src/session.c @@ -42,18 +42,17 @@ #ifdef WIN32 #include /* for socklen_t */ #endif - -#include #ifdef HAVE_UNISTD_H #include #endif -#include -#include - #ifdef HAVE_ALLOCA_H #include #endif +#include +#include +#include + #include "transport.h" #include "session.h" #include "channel.h" diff --git a/src/sftp.c b/src/sftp.c index 6f577378..1da891e2 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -37,14 +37,15 @@ * OF SUCH DAMAGE. */ -#include - #include "libssh2_priv.h" #include "libssh2_sftp.h" + #include "channel.h" #include "session.h" #include "sftp.h" +#include + /* This release of libssh2 implements Version 5 with automatic downgrade * based on server's declaration * https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-05.txt diff --git a/src/transport.c b/src/transport.c index bce6413d..4eeceab3 100644 --- a/src/transport.c +++ b/src/transport.c @@ -39,13 +39,9 @@ */ #include "libssh2_priv.h" -#include -#include -#include -#ifdef LIBSSH2DEBUG -#include -#endif +#include +#include #include #include "transport.h" diff --git a/src/userauth.c b/src/userauth.c index a1c62f69..78b511cc 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -40,9 +40,6 @@ #include "libssh2_priv.h" #include -#include - -#include /* Needed for struct iovec on some platforms */ #ifdef HAVE_SYS_UIO_H diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index cbe08d99..5eab3433 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -41,19 +41,20 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_ARPA_INET_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif -#ifdef HAVE_UNISTD_H -#include -#endif -#include + #include #include #include +#include #if defined(WIN32) && defined(_WIN64) #define LIBSSH2_SOCKET_MASK "%lld" diff --git a/tests/session_fixture.c b/tests/session_fixture.c index 153083e8..922a442b 100644 --- a/tests/session_fixture.c +++ b/tests/session_fixture.c @@ -38,25 +38,25 @@ #include "session_fixture.h" #include "openssh_fixture.h" -#include -#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#include +#include +#include #ifdef _MSC_VER #include #define chdir _chdir #endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#include - static LIBSSH2_SESSION *connected_session = NULL; static libssh2_socket_t connected_socket = LIBSSH2_INVALID_SOCKET; diff --git a/tests/test_ssh2.c b/tests/test_ssh2.c index a1374b8a..2f918cc7 100644 --- a/tests/test_ssh2.c +++ b/tests/test_ssh2.c @@ -17,7 +17,7 @@ #endif #include -#include +#include /* for getenv() */ static const char *hostname = "127.0.0.1"; static const unsigned short port_number = 4711;