diff --git a/scripts/checksrc-all.pl b/scripts/checksrc-all.pl index 6cabac8d..cebc70c1 100755 --- a/scripts/checksrc-all.pl +++ b/scripts/checksrc-all.pl @@ -22,6 +22,7 @@ my @options = ( "-arealloc", "-asnprintf", "-asocket", + "-berrno", ); my @files; diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index 41bf846b..f4bfd7aa 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -343,7 +343,7 @@ while(defined $file) { } elsif($file =~ /^-b(.*)/) { $banfunc{$1} = $1; - print STDERR "ban use of \"$1\"\n"; + # print STDERR "ban use of \"$1\"\n"; $file = shift @ARGV; next; } diff --git a/src/agent.c b/src/agent.c index ed4bcdd0..cfab538a 100644 --- a/src/agent.c +++ b/src/agent.c @@ -41,7 +41,6 @@ #include "libssh2_priv.h" -#include #include /* for getenv() */ #ifdef HAVE_SYS_UN_H diff --git a/src/misc.c b/src/misc.c index 1bf9218c..9531da84 100644 --- a/src/misc.c +++ b/src/misc.c @@ -45,7 +45,6 @@ #include #endif -#include #include #ifdef _WIN32 @@ -163,12 +162,7 @@ ssize_t ssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, rc = SSH2_RECV_LOW(socket, buffer, length, flags); if(rc < 0) { - int err; -#ifdef _WIN32 - err = ssh2_wsa2errno(); -#else - err = errno; -#endif + int err = SSH2_ERRNO(); /* Profiling tools that use SIGPROF can cause EINTR responses. recv() does not modify its arguments when it returns EINTR, but there may be data waiting, so the caller should try again */ @@ -201,12 +195,7 @@ ssize_t ssh2_send(libssh2_socket_t socket, rc = SSH2_SEND_LOW(socket, buffer, length, flags); if(rc < 0) { - int err; -#ifdef _WIN32 - err = ssh2_wsa2errno(); -#else - err = errno; -#endif + int err = SSH2_ERRNO(); /* Profiling tools that use SIGPROF can cause EINTR responses. send() is defined as not yet sending any data when it returns EINTR, so the caller should try again */ diff --git a/src/misc.h b/src/misc.h index 0d6a9f3b..88d66ef7 100644 --- a/src/misc.h +++ b/src/misc.h @@ -39,6 +39,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include + #ifdef LIBSSH2_NO_CLEAR_MEMORY #define ssh2_explicit_zero(buf, size) \ do { \ @@ -83,6 +85,9 @@ int ssh2_err(LIBSSH2_SESSION *session, int errcode, const char *errmsg); #ifdef _WIN32 /* Convert Win32 WSAGetLastError to errno equivalent */ int ssh2_wsa2errno(void); +#define SSH2_ERRNO() ssh2_wsa2errno() +#else +#define SSH2_ERRNO() errno #endif void ssh2_list_init(struct list_head *head); diff --git a/src/session.c b/src/session.c index c54952b8..ccc45097 100644 --- a/src/session.c +++ b/src/session.c @@ -48,7 +48,6 @@ #include #endif -#include #include #include @@ -684,16 +683,10 @@ int ssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) "Timed out waiting on socket"); } if(rc < 0) { - int err; -#ifdef _WIN32 - err = ssh2_wsa2errno(); -#else - err = errno; -#endif /* Profiling tools that use SIGPROF can cause EINTR responses. poll() / select() do not set any descriptor states on EINTR, but some fds may be ready, so the caller should try again */ - if(err == EINTR) + if(SSH2_ERRNO() == EINTR) return 0; return ssh2_err(session, LIBSSH2_ERROR_TIMEOUT, diff --git a/src/transport.c b/src/transport.c index bd90ae21..869fc5a4 100644 --- a/src/transport.c +++ b/src/transport.c @@ -44,7 +44,6 @@ #include "libssh2_priv.h" -#include #include #include