diff options
Diffstat (limited to 'libs/libssh2/src/misc.c')
-rw-r--r-- | libs/libssh2/src/misc.c | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/libs/libssh2/src/misc.c b/libs/libssh2/src/misc.c index b386e3d667..0dee48f5f5 100644 --- a/libs/libssh2/src/misc.c +++ b/libs/libssh2/src/misc.c @@ -40,7 +40,6 @@ */ #include "libssh2_priv.h" -#include "misc.h" #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -49,7 +48,7 @@ #include <errno.h> #include <assert.h> -#ifdef WIN32 +#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)) @@ -73,7 +72,14 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...) if(cp_max_len < 2) return 0; va_start(args, fmt); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif n = vsnprintf(cp, cp_max_len, fmt, args); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif va_end(args); return (n < (int)cp_max_len) ? n : (int)(cp_max_len - 1); } @@ -126,8 +132,8 @@ int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char *errmsg) return _libssh2_error_flags(session, errcode, errmsg, 0); } -#ifdef WIN32 -static int wsa2errno(void) +#ifdef _WIN32 +int _libssh2_wsa2errno(void) { switch(WSAGetLastError()) { case WSAEWOULDBLOCK: @@ -161,23 +167,29 @@ _libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, (void)abstract; rc = recv(sock, buffer, length, flags); -#ifdef WIN32 - if(rc < 0) - return -wsa2errno(); -#else if(rc < 0) { + int err; +#ifdef _WIN32 + err = _libssh2_wsa2errno(); +#else + err = errno; +#endif + /* 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 */ + if(err == EINTR) + return -EAGAIN; /* Sometimes the first recv() function call sets errno to ENOENT on Solaris and HP-UX */ - if(errno == ENOENT) + if(err == ENOENT) return -EAGAIN; #ifdef EWOULDBLOCK /* For VMS and other special unixes */ - else if(errno == EWOULDBLOCK) - return -EAGAIN; + else if(err == EWOULDBLOCK) + return -EAGAIN; #endif else - return -errno; + return -err; } -#endif return rc; } @@ -194,18 +206,24 @@ _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length, (void)abstract; rc = send(sock, buffer, length, flags); -#ifdef WIN32 - if(rc < 0) - return -wsa2errno(); -#else if(rc < 0) { + int err; +#ifdef _WIN32 + err = _libssh2_wsa2errno(); +#else + err = errno; +#endif + /* 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 */ + if(err == EINTR) + return -EAGAIN; #ifdef EWOULDBLOCK /* For VMS and other special unixes */ - if(errno == EWOULDBLOCK) + if(err == EWOULDBLOCK) return -EAGAIN; #endif - return -errno; + return -err; } -#endif return rc; } @@ -557,7 +575,14 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, buflen -= len; msglen = len; va_start(vargs, format); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif len = vsnprintf(buffer + msglen, buflen, format, vargs); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif va_end(vargs); msglen += len < buflen ? len : buflen - 1; } @@ -709,7 +734,7 @@ int _libssh2_gettimeofday(struct timeval *tp, void *tzp) { (void)tzp; if(tp) { -#ifdef WIN32 +#ifdef _WIN32 /* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */ #define _WIN32_FT_OFFSET (116444736000000000) @@ -901,7 +926,6 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf, } } else { - *outlen = 0; *outbuf = NULL; } |