curlx: move Curl_strerror, use in src and tests, ban `strerror` globally
No binary (build failed)
—
(log yok)
| @@ -7,6 +7,7 @@ allowfunc open | |
| allowfunc snprintf | |
| allowfunc socket | |
| allowfunc sscanf | |
| + | allowfunc strerror |
| banfunc curl_maprintf | |
| banfunc curl_mfprintf | |
| banfunc curl_mprintf | |
| @@ -1 +0,0 @@ | |
| - | banfunc strerror |
| @@ -31,6 +31,7 @@ LIB_CURLX_CFILES = \ | |
| curlx/inet_pton.c \ | |
| curlx/multibyte.c \ | |
| curlx/nonblock.c \ | |
| + | curlx/strerr.c \ |
| curlx/strparse.c \ | |
| curlx/timediff.c \ | |
| curlx/timeval.c \ | |
| @@ -49,6 +50,7 @@ LIB_CURLX_HFILES = \ | |
| curlx/inet_pton.h \ | |
| curlx/multibyte.h \ | |
| curlx/nonblock.h \ | |
| + | curlx/strerr.h \ |
| curlx/strparse.h \ | |
| curlx/timediff.h \ | |
| curlx/timeval.h \ | |
| @@ -62,7 +62,6 @@ | |
| #include "bufq.h" | |
| #include "sendf.h" | |
| #include "if2ip.h" | |
| - | #include "strerror.h" |
| #include "cfilters.h" | |
| #include "cf-socket.h" | |
| #include "connect.h" | |
| @@ -80,6 +79,7 @@ | |
| #include "strdup.h" | |
| #include "system_win32.h" | |
| #include "curlx/version_win32.h" | |
| + | #include "curlx/strerr.h" |
| #include "curlx/strparse.h" | |
| /* The last 3 #include files should be in this order */ | |
| @@ -114,7 +114,7 @@ static void tcpnodelay(struct Curl_easy *data, curl_socket_t sockfd) | |
| if(setsockopt(sockfd, level, TCP_NODELAY, | |
| (void *)&onoff, sizeof(onoff)) < 0) | |
| infof(data, "Could not set TCP_NODELAY: %s", | |
| - | Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| #else | |
| (void)data; | |
| (void)sockfd; | |
| @@ -136,7 +136,7 @@ static void nosigpipe(struct Curl_easy *data, | |
| #ifndef CURL_DISABLE_VERBOSE_STRINGS | |
| char buffer[STRERROR_LEN]; | |
| infof(data, "Could not set SO_NOSIGPIPE: %s", | |
| - | Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| #endif | |
| } | |
| } | |
| @@ -644,7 +644,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, | |
| char buffer[STRERROR_LEN]; | |
| data->state.os_errno = error = SOCKERRNO; | |
| failf(data, "Couldn't bind to interface '%s' with errno %d: %s", | |
| - | iface, error, Curl_strerror(error, buffer, sizeof(buffer))); |
| + | iface, error, curlx_strerror(error, buffer, sizeof(buffer))); |
| return CURLE_INTERFACE_FAILED; | |
| } | |
| break; | |
| @@ -747,8 +747,8 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, | |
| char buffer[STRERROR_LEN]; | |
| data->state.errorbuf = FALSE; | |
| data->state.os_errno = error = SOCKERRNO; | |
| - | failf(data, "Couldn't bind to '%s' with errno %d: %s", |
| - | host, error, Curl_strerror(error, buffer, sizeof(buffer))); |
| + | failf(data, "Couldn't bind to '%s' with errno %d: %s", host, |
| + | error, curlx_strerror(error, buffer, sizeof(buffer))); |
| return CURLE_INTERFACE_FAILED; | |
| } | |
| } | |
| @@ -799,7 +799,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, | |
| char buffer[STRERROR_LEN]; | |
| data->state.os_errno = error = SOCKERRNO; | |
| failf(data, "bind failed with errno %d: %s", | |
| - | error, Curl_strerror(error, buffer, sizeof(buffer))); |
| + | error, curlx_strerror(error, buffer, sizeof(buffer))); |
| } | |
| return CURLE_INTERFACE_FAILED; | |
| @@ -900,8 +900,8 @@ static CURLcode socket_connect_result(struct Curl_easy *data, | |
| #else | |
| { | |
| char buffer[STRERROR_LEN]; | |
| - | infof(data, "Immediate connect fail for %s: %s", |
| - | ipaddress, Curl_strerror(error, buffer, sizeof(buffer))); |
| + | infof(data, "Immediate connect fail for %s: %s", ipaddress, |
| + | curlx_strerror(error, buffer, sizeof(buffer))); |
| } | |
| #endif | |
| data->state.os_errno = error; | |
| @@ -1050,13 +1050,13 @@ static CURLcode set_local_ip(struct Curl_cfilter *cf, | |
| if(getsockname(ctx->sock, (struct sockaddr*) &ssloc, &slen)) { | |
| int error = SOCKERRNO; | |
| failf(data, "getsockname() failed with errno %d: %s", | |
| - | error, Curl_strerror(error, buffer, sizeof(buffer))); |
| + | error, curlx_strerror(error, buffer, sizeof(buffer))); |
| return CURLE_FAILED_INIT; | |
| } | |
| if(!Curl_addr2string((struct sockaddr*)&ssloc, slen, | |
| ctx->ip.local_ip, &ctx->ip.local_port)) { | |
| failf(data, "ssloc inet_ntop() failed with errno %d: %s", | |
| - | errno, Curl_strerror(errno, buffer, sizeof(buffer))); |
| + | errno, curlx_strerror(errno, buffer, sizeof(buffer))); |
| return CURLE_FAILED_INIT; | |
| } | |
| } | |
| @@ -1082,7 +1082,7 @@ static CURLcode set_remote_ip(struct Curl_cfilter *cf, | |
| ctx->error = errno; | |
| /* malformed address or bug in inet_ntop, try next address */ | |
| failf(data, "curl_sa_addr inet_ntop() failed with errno %d: %s", | |
| - | errno, Curl_strerror(errno, buffer, sizeof(buffer))); |
| + | errno, curlx_strerror(errno, buffer, sizeof(buffer))); |
| return CURLE_FAILED_INIT; | |
| } | |
| return CURLE_OK; | |
| @@ -1360,7 +1360,7 @@ out: | |
| infof(data, "connect to %s port %u from %s port %d failed: %s", | |
| ctx->ip.remote_ip, ctx->ip.remote_port, | |
| ctx->ip.local_ip, ctx->ip.local_port, | |
| - | Curl_strerror(ctx->error, buffer, sizeof(buffer))); |
| + | curlx_strerror(ctx->error, buffer, sizeof(buffer))); |
| } | |
| #endif | |
| } | |
| @@ -1498,7 +1498,7 @@ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, | |
| else { | |
| char buffer[STRERROR_LEN]; | |
| failf(data, "Send failure: %s", | |
| - | Curl_strerror(sockerr, buffer, sizeof(buffer))); |
| + | curlx_strerror(sockerr, buffer, sizeof(buffer))); |
| data->state.os_errno = sockerr; | |
| result = CURLE_SEND_ERROR; | |
| } | |
| @@ -1566,7 +1566,7 @@ static CURLcode cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data, | |
| else { | |
| char buffer[STRERROR_LEN]; | |
| failf(data, "Recv failure: %s", | |
| - | Curl_strerror(sockerr, buffer, sizeof(buffer))); |
| + | curlx_strerror(sockerr, buffer, sizeof(buffer))); |
| data->state.os_errno = sockerr; | |
| result = CURLE_RECV_ERROR; | |
| } | |
| @@ -2037,13 +2037,13 @@ static void cf_tcp_set_accepted_remote_ip(struct Curl_cfilter *cf, | |
| if(getpeername(ctx->sock, (struct sockaddr*) &ssrem, &plen)) { | |
| int error = SOCKERRNO; | |
| failf(data, "getpeername() failed with errno %d: %s", | |
| - | error, Curl_strerror(error, buffer, sizeof(buffer))); |
| + | error, curlx_strerror(error, buffer, sizeof(buffer))); |
| return; | |
| } | |
| if(!Curl_addr2string((struct sockaddr*)&ssrem, plen, | |
| ctx->ip.remote_ip, &ctx->ip.remote_port)) { | |
| failf(data, "ssrem inet_ntop() failed with errno %d: %s", | |
| - | errno, Curl_strerror(errno, buffer, sizeof(buffer))); |
| + | errno, curlx_strerror(errno, buffer, sizeof(buffer))); |
| return; | |
| } | |
| #else | |
| @@ -950,6 +950,10 @@ endings either CRLF or LF so 't' is appropriate. | |
| #define CURL_ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) | |
| + | /* Buffer size for error messages retrieved via |
| + | curlx_strerror() and Curl_sspi_strerror() */ |
| + | #define STRERROR_LEN 256 |
| + | |
| #ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS /* only if not already done */ | |
| /* | |
| * The following memory function replacement typedef's are COPIED from | |
| @@ -1 +0,0 @@ | |
| - | banfunc strerror |
| @@ -58,6 +58,9 @@ | |
| #include "version_win32.h" | |
| /* provides curlx_verify_windows_version() */ | |
| + | #include "strerr.h" |
| + | /* The curlx_strerror() function */ |
| + | |
| #include "strparse.h" | |
| /* The curlx_str_* parsing functions */ | |
| @@ -0,0 +1,361 @@ | |
| + | /*************************************************************************** |
| + | * _ _ ____ _ |
| + | * Project ___| | | | _ \| | |
| + | * / __| | | | |_) | | |
| + | * | (__| |_| | _ <| |___ |
| + | * \___|\___/|_| \_\_____| |
| + | * |
| + | * Copyright (C) Daniel Stenberg, <[email protected]>, et al. |
| + | * |
| + | * This software is licensed as described in the file COPYING, which |
| + | * you should have received as part of this distribution. The terms |
| + | * are also available at https://curl.se/docs/copyright.html. |
| + | * |
| + | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| + | * copies of the Software, and permit persons to whom the Software is |
| + | * furnished to do so, under the terms of the COPYING file. |
| + | * |
| + | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| + | * KIND, either express or implied. |
| + | * |
| + | * SPDX-License-Identifier: curl |
| + | * |
| + | ***************************************************************************/ |
| + | |
| + | #include "../curl_setup.h" |
| + | |
| + | #ifdef HAVE_STRERROR_R |
| + | # if (!defined(HAVE_POSIX_STRERROR_R) && \ |
| + | !defined(HAVE_GLIBC_STRERROR_R)) || \ |
| + | (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)) |
| + | # error "strerror_r MUST be either POSIX, glibc style" |
| + | # endif |
| + | #endif |
| + | |
| + | #include <curl/curl.h> |
| + | |
| + | #ifndef WITHOUT_LIBCURL |
| + | #include <curl/mprintf.h> |
| + | #define SNPRINTF curl_msnprintf |
| + | #else |
| + | /* when built for the test servers */ |
| + | |
| + | /* adjust for old MSVC */ |
| + | #if defined(_MSC_VER) && (_MSC_VER < 1900) |
| + | #define SNPRINTF _snprintf |
| + | #else |
| + | #define SNPRINTF snprintf |
| + | #endif |
| + | #endif /* !WITHOUT_LIBCURL */ |
| + | |
| + | #include "winapi.h" |
| + | #include "strerr.h" |
| + | /* The last 2 #include files should be in this order */ |
| + | #include "../curl_memory.h" |
| + | #include "../memdebug.h" |
| + | |
| + | #ifdef USE_WINSOCK |
| + | /* This is a helper function for curlx_strerror that converts Winsock error |
| + | * codes (WSAGetLastError) to error messages. |
| + | * Returns NULL if no error message was found for error code. |
| + | */ |
| + | static const char * |
| + | get_winsock_error(int err, char *buf, size_t len) |
| + | { |
| + | #ifndef CURL_DISABLE_VERBOSE_STRINGS |
| + | const char *p; |
| + | size_t alen; |
| + | #endif |
| + | |
| + | if(!len) |
| + | return NULL; |
| + | |
| + | *buf = '\0'; |
| + | |
| + | #ifdef CURL_DISABLE_VERBOSE_STRINGS |
| + | (void)err; |
| + | return NULL; |
| + | #else |
| + | switch(err) { |
| + | case WSAEINTR: |
| + | p = "Call interrupted"; |
| + | break; |
| + | case WSAEBADF: |
| + | p = "Bad file"; |
| + | break; |
| + | case WSAEACCES: |
| + | p = "Bad access"; |
| + | break; |
| + | case WSAEFAULT: |
| + | p = "Bad argument"; |
| + | break; |
| + | case WSAEINVAL: |
| + | p = "Invalid arguments"; |
| + | break; |
| + | case WSAEMFILE: |
| + | p = "Out of file descriptors"; |
| + | break; |
| + | case WSAEWOULDBLOCK: |
| + | p = "Call would block"; |
| + | break; |
| + | case WSAEINPROGRESS: |
| + | case WSAEALREADY: |
| + | p = "Blocking call in progress"; |
| + | break; |
| + | case WSAENOTSOCK: |
| + | p = "Descriptor is not a socket"; |
| + | break; |
| + | case WSAEDESTADDRREQ: |
| + | p = "Need destination address"; |
| + | break; |
| + | case WSAEMSGSIZE: |
| + | p = "Bad message size"; |
| + | break; |
| + | case WSAEPROTOTYPE: |
| + | p = "Bad protocol"; |
| + | break; |
| + | case WSAENOPROTOOPT: |
| + | p = "Protocol option is unsupported"; |
| + | break; |
| + | case WSAEPROTONOSUPPORT: |
| + | p = "Protocol is unsupported"; |
| + | break; |
| + | case WSAESOCKTNOSUPPORT: |
| + | p = "Socket is unsupported"; |
| + | break; |
| + | case WSAEOPNOTSUPP: |
| + | p = "Operation not supported"; |
| + | break; |
| + | case WSAEAFNOSUPPORT: |
| + | p = "Address family not supported"; |
| + | break; |
| + | case WSAEPFNOSUPPORT: |
| + | p = "Protocol family not supported"; |
| + | break; |
| + | case WSAEADDRINUSE: |
| + | p = "Address already in use"; |
| + | break; |
| + | case WSAEADDRNOTAVAIL: |
| + | p = "Address not available"; |
| + | break; |
| + | case WSAENETDOWN: |
| + | p = "Network down"; |
| + | break; |
| + | case WSAENETUNREACH: |
| + | p = "Network unreachable"; |
| + | break; |
| + | case WSAENETRESET: |
| + | p = "Network has been reset"; |
| + | break; |
| + | case WSAECONNABORTED: |
| + | p = "Connection was aborted"; |
| + | break; |
| + | case WSAECONNRESET: |
| + | p = "Connection was reset"; |
| + | break; |
| + | case WSAENOBUFS: |
| + | p = "No buffer space"; |
| + | break; |
| + | case WSAEISCONN: |
| + | p = "Socket is already connected"; |
| + | break; |
| + | case WSAENOTCONN: |
| + | p = "Socket is not connected"; |
| + | break; |
| + | case WSAESHUTDOWN: |
| + | p = "Socket has been shut down"; |
| + | break; |
| + | case WSAETOOMANYREFS: |
| + | p = "Too many references"; |
| + | break; |
| + | case WSAETIMEDOUT: |
| + | p = "Timed out"; |
| + | break; |
| + | case WSAECONNREFUSED: |
| + | p = "Connection refused"; |
| + | break; |
| + | case WSAELOOP: |
| + | p = "Loop??"; |
| + | break; |
| + | case WSAENAMETOOLONG: |
| + | p = "Name too long"; |
| + | break; |
| + | case WSAEHOSTDOWN: |
| + | p = "Host down"; |
| + | break; |
| + | case WSAEHOSTUNREACH: |
| + | p = "Host unreachable"; |
| + | break; |
| + | case WSAENOTEMPTY: |
| + | p = "Not empty"; |
| + | break; |
| + | case WSAEPROCLIM: |
| + | p = "Process limit reached"; |
| + | break; |
| + | case WSAEUSERS: |
| + | p = "Too many users"; |
| + | break; |
| + | case WSAEDQUOT: |
| + | p = "Bad quota"; |
| + | break; |
| + | case WSAESTALE: |
| + | p = "Something is stale"; |
| + | break; |
| + | case WSAEREMOTE: |
| + | p = "Remote error"; |
| + | break; |
| + | case WSAEDISCON: |
| + | p = "Disconnected"; |
| + | break; |
| + | /* Extended Winsock errors */ |
| + | case WSASYSNOTREADY: |
| + | p = "Winsock library is not ready"; |
| + | break; |
| + | case WSANOTINITIALISED: |
| + | p = "Winsock library not initialised"; |
| + | break; |
| + | case WSAVERNOTSUPPORTED: |
| + | p = "Winsock version not supported"; |
| + | break; |
| + | |
| + | /* getXbyY() errors (already handled in herrmsg): |
| + | * Authoritative Answer: Host not found */ |
| + | case WSAHOST_NOT_FOUND: |
| + | p = "Host not found"; |
| + | break; |
| + | |
| + | /* Non-Authoritative: Host not found, or SERVERFAIL */ |
| + | case WSATRY_AGAIN: |
| + | p = "Host not found, try again"; |
| + | break; |
| + | |
| + | /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ |
| + | case WSANO_RECOVERY: |
| + | p = "Unrecoverable error in call to nameserver"; |
| + | break; |
| + | |
| + | /* Valid name, no data record of requested type */ |
| + | case WSANO_DATA: |
| + | p = "No data record of requested type"; |
| + | break; |
| + | |
| + | default: |
| + | return NULL; |
| + | } |
| + | alen = strlen(p); |
| + | if(alen < len) |
| + | strcpy(buf, p); |
| + | return buf; |
| + | #endif |
| + | } |
| + | #endif /* USE_WINSOCK */ |
| + | |
| + | /* |
| + | * Our thread-safe and smart strerror() replacement. |
| + | * |
| + | * The 'err' argument passed in to this function MUST be a true errno number |
| + | * as reported on this system. We do no range checking on the number before |
| + | * we pass it to the "number-to-message" conversion function and there might |
| + | * be systems that do not do proper range checking in there themselves. |
| + | * |
| + | * We do not do range checking (on systems other than Windows) since there is |
| + | * no good reliable and portable way to do it. |
| + | * |
| + | * On Windows different types of error codes overlap. This function has an |
| + | * order of preference when trying to match error codes: |
| + | * CRT (errno), Winsock (WSAGetLastError), Windows API (GetLastError). |
| + | * |
| + | * It may be more correct to call one of the variant functions instead: |
| + | * Call Curl_sspi_strerror if the error code is definitely Windows SSPI. |
| + | * Call curlx_winapi_strerror if the error code is definitely Windows API. |
| + | */ |
| + | const char *curlx_strerror(int err, char *buf, size_t buflen) |
| + | { |
| + | #ifdef _WIN32 |
| + | DWORD old_win_err = GetLastError(); |
| + | #endif |
| + | int old_errno = errno; |
| + | char *p; |
| + | |
| + | if(!buflen) |
| + | return NULL; |
| + | |
| + | #ifndef _WIN32 |
| + | DEBUGASSERT(err >= 0); |
| + | #endif |
| + | |
| + | *buf = '\0'; |
| + | |
| + | #ifdef _WIN32 |
| + | #ifndef UNDER_CE |
| + | /* 'sys_nerr' is the maximum errno number, it is not widely portable */ |
| + | if(err >= 0 && err < sys_nerr) |
| + | SNPRINTF(buf, buflen, "%s", sys_errlist[err]); |
| + | else |
| + | #endif |
| + | { |
| + | if( |
| + | #ifdef USE_WINSOCK |
| + | !get_winsock_error(err, buf, buflen) && |
| + | #endif |
| + | !curlx_get_winapi_error(err, buf, buflen)) |
| + | SNPRINTF(buf, buflen, "Unknown error %d (%#x)", err, err); |
| + | } |
| + | #else /* !_WIN32 */ |
| + | |
| + | #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R) |
| + | /* |
| + | * The POSIX-style strerror_r() may set errno to ERANGE if insufficient |
| + | * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated |
| + | * message string, or EINVAL if 'errnum' is not a valid error number. |
| + | */ |
| + | if(strerror_r(err, buf, buflen) && |
| + | buflen > sizeof("Unknown error ") + 20) { |
| + | if(buf[0] == '\0') |
| + | SNPRINTF(buf, buflen, "Unknown error %d", err); |
| + | } |
| + | #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R) |
| + | /* |
| + | * The glibc-style strerror_r() only *might* use the buffer we pass to |
| + | * the function, but it always returns the error message as a pointer, |
| + | * so we must copy that string unconditionally (if non-NULL). |
| + | */ |
| + | { |
| + | char buffer[256]; |
| + | char *msg = strerror_r(err, buffer, sizeof(buffer)); |
| + | if(msg && buflen > 1) |
| + | SNPRINTF(buf, buflen, "%s", msg); |
| + | else if(buflen > sizeof("Unknown error ") + 20) |
| + | SNPRINTF(buf, buflen, "Unknown error %d", err); |
| + | } |
| + | #else |
| + | { |
| + | /* !checksrc! disable BANNEDFUNC 1 */ |
| + | const char *msg = strerror(err); |
| + | if(msg && buflen > 1) |
| + | SNPRINTF(buf, buflen, "%s", msg); |
| + | else if(buflen > sizeof("Unknown error ") + 20) |
| + | SNPRINTF(buf, buflen, "Unknown error %d", err); |
| + | } |
| + | #endif |
| + | |
| + | #endif /* _WIN32 */ |
| + | |
| + | /* strip trailing '\r\n' or '\n'. */ |
| + | p = strrchr(buf, '\n'); |
| + | if(p && (p - buf) >= 2) |
| + | *p = '\0'; |
| + | p = strrchr(buf, '\r'); |
| + | if(p && (p - buf) >= 1) |
| + | *p = '\0'; |
| + | |
| + | if(errno != old_errno) |
| + | CURL_SETERRNO(old_errno); |
| + | |
| + | #ifdef _WIN32 |
| + | if(old_win_err != GetLastError()) |
| + | SetLastError(old_win_err); |
| + | #endif |
| + | |
| + | return buf; |
| + | } |
| @@ -0,0 +1,29 @@ | |
| + | #ifndef HEADER_CURL_STRERR_H |
| + | #define HEADER_CURL_STRERR_H |
| + | /*************************************************************************** |
| + | * _ _ ____ _ |
| + | * Project ___| | | | _ \| | |
| + | * / __| | | | |_) | | |
| + | * | (__| |_| | _ <| |___ |
| + | * \___|\___/|_| \_\_____| |
| + | * |
| + | * Copyright (C) Daniel Stenberg, <[email protected]>, et al. |
| + | * |
| + | * This software is licensed as described in the file COPYING, which |
| + | * you should have received as part of this distribution. The terms |
| + | * are also available at https://curl.se/docs/copyright.html. |
| + | * |
| + | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| + | * copies of the Software, and permit persons to whom the Software is |
| + | * furnished to do so, under the terms of the COPYING file. |
| + | * |
| + | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| + | * KIND, either express or implied. |
| + | * |
| + | * SPDX-License-Identifier: curl |
| + | * |
| + | ***************************************************************************/ |
| + | |
| + | const char *curlx_strerror(int err, char *buf, size_t buflen); |
| + | |
| + | #endif /* HEADER_CURL_STRERR_H */ |
| @@ -25,12 +25,12 @@ | |
| /* | |
| * curlx_winapi_strerror: | |
| - | * Variant of Curl_strerror if the error code is definitely Windows API. |
| + | * Variant of curlx_strerror if the error code is definitely Windows API. |
| */ | |
| #ifdef _WIN32 | |
| #include "winapi.h" | |
| - | #ifdef BUILDING_LIBCURL |
| + | #ifndef WITHOUT_LIBCURL |
| #include <curl/mprintf.h> | |
| #define SNPRINTF curl_msnprintf | |
| #else | |
| @@ -42,10 +42,9 @@ | |
| #else | |
| #define SNPRINTF snprintf | |
| #endif | |
| + | #endif /* !WITHOUT_LIBCURL */ |
| - | #endif /* !BUILDING_LIBCURL */ |
| - | |
| - | /* This is a helper function for Curl_strerror that converts Windows API error |
| + | /* This is a helper function for curlx_strerror that converts Windows API error |
| * codes (GetLastError) to error messages. | |
| * Returns NULL if no error message was found for error code. | |
| */ | |
| @@ -58,7 +58,6 @@ | |
| #include "cfilters.h" | |
| #include "cf-socket.h" | |
| #include "connect.h" | |
| - | #include "strerror.h" |
| #include "curlx/inet_ntop.h" | |
| #include "curlx/inet_pton.h" | |
| #include "select.h" | |
| @@ -71,6 +70,7 @@ | |
| #include "http_proxy.h" | |
| #include "socks.h" | |
| #include "strdup.h" | |
| + | #include "curlx/strerr.h" |
| #include "curlx/strparse.h" | |
| /* The last 3 #include files should be in this order */ | |
| #include "curl_printf.h" | |
| @@ -1007,7 +1007,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, | |
| sslen = sizeof(ss); | |
| if(getsockname(conn->sock[FIRSTSOCKET], sa, &sslen)) { | |
| failf(data, "getsockname() failed: %s", | |
| - | Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| goto out; | |
| } | |
| switch(sa->sa_family) { | |
| @@ -1054,7 +1054,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, | |
| } | |
| if(!ai) { | |
| failf(data, "socket failure: %s", | |
| - | Curl_strerror(error, buffer, sizeof(buffer))); |
| + | curlx_strerror(error, buffer, sizeof(buffer))); |
| goto out; | |
| } | |
| CURL_TRC_FTP(data, "[%s] ftp_state_use_port(), opened socket", | |
| @@ -1081,12 +1081,12 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, | |
| * the control connection instead and restart the port loop | |
| */ | |
| infof(data, "bind(port=%hu) on non-local address failed: %s", port, | |
| - | Curl_strerror(error, buffer, sizeof(buffer))); |
| + | curlx_strerror(error, buffer, sizeof(buffer))); |
| sslen = sizeof(ss); | |
| if(getsockname(conn->sock[FIRSTSOCKET], sa, &sslen)) { | |
| failf(data, "getsockname() failed: %s", | |
| - | Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| goto out; | |
| } | |
| port = port_min; | |
| @@ -1095,7 +1095,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, | |
| } | |
| if(error != SOCKEADDRINUSE && error != SOCKEACCES) { | |
| failf(data, "bind(port=%hu) failed: %s", port, | |
| - | Curl_strerror(error, buffer, sizeof(buffer))); |
| + | curlx_strerror(error, buffer, sizeof(buffer))); |
| goto out; | |
| } | |
| } | |
| @@ -1118,7 +1118,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, | |
| sslen = sizeof(ss); | |
| if(getsockname(portsock, sa, &sslen)) { | |
| failf(data, "getsockname() failed: %s", | |
| - | Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| goto out; | |
| } | |
| CURL_TRC_FTP(data, "[%s] ftp_state_use_port(), socket bound to port %d", | |
| @@ -1128,7 +1128,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, | |
| if(listen(portsock, 1)) { | |
| failf(data, "socket failure: %s", | |
| - | Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| goto out; | |
| } | |
| CURL_TRC_FTP(data, "[%s] ftp_state_use_port(), listening on %d", | |
| @@ -24,15 +24,8 @@ | |
| #include "curl_setup.h" | |
| - | #ifdef HAVE_STRERROR_R |
| - | # if (!defined(HAVE_POSIX_STRERROR_R) && \ |
| - | !defined(HAVE_GLIBC_STRERROR_R)) || \ |
| - | (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)) |
| - | # error "strerror_r MUST be either POSIX, glibc style" |
| - | # endif |
| - | #endif |
| - | |
| #include <curl/curl.h> | |
| + | #include <curl/mprintf.h> |
| #ifdef USE_WINDOWS_SSPI | |
| #include "curl_sspi.h" | |
| @@ -40,8 +33,8 @@ | |
| #include "curlx/winapi.h" | |
| #include "strerror.h" | |
| - | /* The last 3 #include files should be in this order */ |
| - | #include "curl_printf.h" |
| + | |
| + | /* The last 2 #include files should be in this order */ |
| #include "curl_memory.h" | |
| #include "memdebug.h" | |
| @@ -548,315 +541,10 @@ curl_url_strerror(CURLUcode error) | |
| #endif | |
| } | |
| - | #ifdef USE_WINSOCK |
| - | /* This is a helper function for Curl_strerror that converts Winsock error |
| - | * codes (WSAGetLastError) to error messages. |
| - | * Returns NULL if no error message was found for error code. |
| - | */ |
| - | static const char * |
| - | get_winsock_error(int err, char *buf, size_t len) |
| - | { |
| - | #ifndef CURL_DISABLE_VERBOSE_STRINGS |
| - | const char *p; |
| - | size_t alen; |
| - | #endif |
| - | |
| - | if(!len) |
| - | return NULL; |
| - | |
| - | *buf = '\0'; |
| - | |
| - | #ifdef CURL_DISABLE_VERBOSE_STRINGS |
| - | (void)err; |
| - | return NULL; |
| - | #else |
| - | switch(err) { |
| - | case WSAEINTR: |
| - | p = "Call interrupted"; |
| - | break; |
| - | case WSAEBADF: |
| - | p = "Bad file"; |
| - | break; |
| - | case WSAEACCES: |
| - | p = "Bad access"; |
| - | break; |
| - | case WSAEFAULT: |
| - | p = "Bad argument"; |
| - | break; |
| - | case WSAEINVAL: |
| - | p = "Invalid arguments"; |
| - | break; |
| - | case WSAEMFILE: |
| - | p = "Out of file descriptors"; |
| - | break; |
| - | case WSAEWOULDBLOCK: |
| - | p = "Call would block"; |
| - | break; |
| - | case WSAEINPROGRESS: |
| - | case WSAEALREADY: |
| - | p = "Blocking call in progress"; |
| - | break; |
| - | case WSAENOTSOCK: |
| - | p = "Descriptor is not a socket"; |
| - | break; |
| - | case WSAEDESTADDRREQ: |
| - | p = "Need destination address"; |
| - | break; |
| - | case WSAEMSGSIZE: |
| - | p = "Bad message size"; |
| - | break; |
| - | case WSAEPROTOTYPE: |
| - | p = "Bad protocol"; |
| - | break; |
| - | case WSAENOPROTOOPT: |
| - | p = "Protocol option is unsupported"; |
| - | break; |
| - | case WSAEPROTONOSUPPORT: |
| - | p = "Protocol is unsupported"; |
| - | break; |
| - | case WSAESOCKTNOSUPPORT: |
| - | p = "Socket is unsupported"; |
| - | break; |
| - | case WSAEOPNOTSUPP: |
| - | p = "Operation not supported"; |
| - | break; |
| - | case WSAEAFNOSUPPORT: |
| - | p = "Address family not supported"; |
| - | break; |
| - | case WSAEPFNOSUPPORT: |
| - | p = "Protocol family not supported"; |
| - | break; |
| - | case WSAEADDRINUSE: |
| - | p = "Address already in use"; |
| - | break; |
| - | case WSAEADDRNOTAVAIL: |
| - | p = "Address not available"; |
| - | break; |
| - | case WSAENETDOWN: |
| - | p = "Network down"; |
| - | break; |
| - | case WSAENETUNREACH: |
| - | p = "Network unreachable"; |
| - | break; |
| - | case WSAENETRESET: |
| - | p = "Network has been reset"; |
| - | break; |
| - | case WSAECONNABORTED: |
| - | p = "Connection was aborted"; |
| - | break; |
| - | case WSAECONNRESET: |
| - | p = "Connection was reset"; |
| - | break; |
| - | case WSAENOBUFS: |
| - | p = "No buffer space"; |
| - | break; |
| - | case WSAEISCONN: |
| - | p = "Socket is already connected"; |
| - | break; |
| - | case WSAENOTCONN: |
| - | p = "Socket is not connected"; |
| - | break; |
| - | case WSAESHUTDOWN: |
| - | p = "Socket has been shut down"; |
| - | break; |
| - | case WSAETOOMANYREFS: |
| - | p = "Too many references"; |
| - | break; |
| - | case WSAETIMEDOUT: |
| - | p = "Timed out"; |
| - | break; |
| - | case WSAECONNREFUSED: |
| - | p = "Connection refused"; |
| - | break; |
| - | case WSAELOOP: |
| - | p = "Loop??"; |
| - | break; |
| - | case WSAENAMETOOLONG: |
| - | p = "Name too long"; |
| - | break; |
| - | case WSAEHOSTDOWN: |
| - | p = "Host down"; |
| - | break; |
| - | case WSAEHOSTUNREACH: |
| - | p = "Host unreachable"; |
| - | break; |
| - | case WSAENOTEMPTY: |
| - | p = "Not empty"; |
| - | break; |
| - | case WSAEPROCLIM: |
| - | p = "Process limit reached"; |
| - | break; |
| - | case WSAEUSERS: |
| - | p = "Too many users"; |
| - | break; |
| - | case WSAEDQUOT: |
| - | p = "Bad quota"; |
| - | break; |
| - | case WSAESTALE: |
| - | p = "Something is stale"; |
| - | break; |
| - | case WSAEREMOTE: |
| - | p = "Remote error"; |
| - | break; |
| - | case WSAEDISCON: |
| - | p = "Disconnected"; |
| - | break; |
| - | /* Extended Winsock errors */ |
| - | case WSASYSNOTREADY: |
| - | p = "Winsock library is not ready"; |
| - | break; |
| - | case WSANOTINITIALISED: |
| - | p = "Winsock library not initialised"; |
| - | break; |
| - | case WSAVERNOTSUPPORTED: |
| - | p = "Winsock version not supported"; |
| - | break; |
| - | |
| - | /* getXbyY() errors (already handled in herrmsg): |
| - | * Authoritative Answer: Host not found */ |
| - | case WSAHOST_NOT_FOUND: |
| - | p = "Host not found"; |
| - | break; |
| - | |
| - | /* Non-Authoritative: Host not found, or SERVERFAIL */ |
| - | case WSATRY_AGAIN: |
| - | p = "Host not found, try again"; |
| - | break; |
| - | |
| - | /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ |
| - | case WSANO_RECOVERY: |
| - | p = "Unrecoverable error in call to nameserver"; |
| - | break; |
| - | |
| - | /* Valid name, no data record of requested type */ |
| - | case WSANO_DATA: |
| - | p = "No data record of requested type"; |
| - | break; |
| - | |
| - | default: |
| - | return NULL; |
| - | } |
| - | alen = strlen(p); |
| - | if(alen < len) |
| - | strcpy(buf, p); |
| - | return buf; |
| - | #endif |
| - | } |
| - | #endif /* USE_WINSOCK */ |
| - | |
| - | /* |
| - | * Our thread-safe and smart strerror() replacement. |
| - | * |
| - | * The 'err' argument passed in to this function MUST be a true errno number |
| - | * as reported on this system. We do no range checking on the number before |
| - | * we pass it to the "number-to-message" conversion function and there might |
| - | * be systems that do not do proper range checking in there themselves. |
| - | * |
| - | * We do not do range checking (on systems other than Windows) since there is |
| - | * no good reliable and portable way to do it. |
| - | * |
| - | * On Windows different types of error codes overlap. This function has an |
| - | * order of preference when trying to match error codes: |
| - | * CRT (errno), Winsock (WSAGetLastError), Windows API (GetLastError). |
| - | * |
| - | * It may be more correct to call one of the variant functions instead: |
| - | * Call Curl_sspi_strerror if the error code is definitely Windows SSPI. |
| - | * Call curlx_winapi_strerror if the error code is definitely Windows API. |
| - | */ |
| - | const char *Curl_strerror(int err, char *buf, size_t buflen) |
| - | { |
| - | #ifdef _WIN32 |
| - | DWORD old_win_err = GetLastError(); |
| - | #endif |
| - | int old_errno = errno; |
| - | char *p; |
| - | |
| - | if(!buflen) |
| - | return NULL; |
| - | |
| - | #ifndef _WIN32 |
| - | DEBUGASSERT(err >= 0); |
| - | #endif |
| - | |
| - | *buf = '\0'; |
| - | |
| - | #ifdef _WIN32 |
| - | #ifndef UNDER_CE |
| - | /* 'sys_nerr' is the maximum errno number, it is not widely portable */ |
| - | if(err >= 0 && err < sys_nerr) |
| - | curl_msnprintf(buf, buflen, "%s", sys_errlist[err]); |
| - | else |
| - | #endif |
| - | { |
| - | if( |
| - | #ifdef USE_WINSOCK |
| - | !get_winsock_error(err, buf, buflen) && |
| - | #endif |
| - | !curlx_get_winapi_error(err, buf, buflen)) |
| - | curl_msnprintf(buf, buflen, "Unknown error %d (%#x)", err, err); |
| - | } |
| - | #else /* not Windows coming up */ |
| - | |
| - | #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R) |
| - | /* |
| - | * The POSIX-style strerror_r() may set errno to ERANGE if insufficient |
| - | * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated |
| - | * message string, or EINVAL if 'errnum' is not a valid error number. |
| - | */ |
| - | if(strerror_r(err, buf, buflen)) { |
| - | if('\0' == buf[0]) |
| - | curl_msnprintf(buf, buflen, "Unknown error %d", err); |
| - | } |
| - | #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R) |
| - | /* |
| - | * The glibc-style strerror_r() only *might* use the buffer we pass to |
| - | * the function, but it always returns the error message as a pointer, |
| - | * so we must copy that string unconditionally (if non-NULL). |
| - | */ |
| - | { |
| - | char buffer[256]; |
| - | char *msg = strerror_r(err, buffer, sizeof(buffer)); |
| - | if(msg) |
| - | curl_msnprintf(buf, buflen, "%s", msg); |
| - | else |
| - | curl_msnprintf(buf, buflen, "Unknown error %d", err); |
| - | } |
| - | #else |
| - | { |
| - | /* !checksrc! disable BANNEDFUNC 1 */ |
| - | const char *msg = strerror(err); |
| - | if(msg) |
| - | curl_msnprintf(buf, buflen, "%s", msg); |
| - | else |
| - | curl_msnprintf(buf, buflen, "Unknown error %d", err); |
| - | } |
| - | #endif |
| - | |
| - | #endif /* end of not Windows */ |
| - | |
| - | /* strip trailing '\r\n' or '\n'. */ |
| - | p = strrchr(buf, '\n'); |
| - | if(p && (p - buf) >= 2) |
| - | *p = '\0'; |
| - | p = strrchr(buf, '\r'); |
| - | if(p && (p - buf) >= 1) |
| - | *p = '\0'; |
| - | |
| - | if(errno != old_errno) |
| - | CURL_SETERRNO(old_errno); |
| - | |
| - | #ifdef _WIN32 |
| - | if(old_win_err != GetLastError()) |
| - | SetLastError(old_win_err); |
| - | #endif |
| - | |
| - | return buf; |
| - | } |
| - | |
| #ifdef USE_WINDOWS_SSPI | |
| /* | |
| * Curl_sspi_strerror: | |
| - | * Variant of Curl_strerror if the error code is definitely Windows SSPI. |
| + | * Variant of curlx_strerror if the error code is definitely Windows SSPI. |
| */ | |
| const char *Curl_sspi_strerror(int err, char *buf, size_t buflen) | |
| { | |
| @@ -24,11 +24,6 @@ | |
| * | |
| ***************************************************************************/ | |
| - | #include "urldata.h" |
| - | |
| - | #define STRERROR_LEN 256 /* a suitable length */ |
| - | |
| - | const char *Curl_strerror(int err, char *buf, size_t buflen); |
| #ifdef USE_WINDOWS_SSPI | |
| const char *Curl_sspi_strerror(int err, char *buf, size_t buflen); | |
| #endif | |
| @@ -55,7 +55,6 @@ | |
| #include "tftp.h" | |
| #include "progress.h" | |
| #include "connect.h" | |
| - | #include "strerror.h" |
| #include "sockaddr.h" /* required for Curl_sockaddr_storage */ | |
| #include "multiif.h" | |
| #include "url.h" | |
| @@ -63,6 +62,7 @@ | |
| #include "speedcheck.h" | |
| #include "select.h" | |
| #include "escape.h" | |
| + | #include "curlx/strerr.h" |
| #include "curlx/strparse.h" | |
| /* The last 3 #include files should be in this order */ | |
| @@ -539,7 +539,7 @@ static CURLcode tftp_send_first(struct tftp_conn *state, | |
| free(filename); | |
| if(senddata != (ssize_t)sbytes) { | |
| char buffer[STRERROR_LEN]; | |
| - | failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | failf(data, "%s", curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| return CURLE_SEND_ERROR; | |
| } | |
| break; | |
| @@ -622,7 +622,7 @@ static CURLcode tftp_rx(struct tftp_conn *state, tftp_event_t event) | |
| (struct sockaddr *)&state->remote_addr, | |
| state->remote_addrlen); | |
| if(sbytes < 0) { | |
| - | failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | failf(data, "%s", curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| return CURLE_SEND_ERROR; | |
| } | |
| @@ -647,7 +647,7 @@ static CURLcode tftp_rx(struct tftp_conn *state, tftp_event_t event) | |
| (struct sockaddr *)&state->remote_addr, | |
| state->remote_addrlen); | |
| if(sbytes < 0) { | |
| - | failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | failf(data, "%s", curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| return CURLE_SEND_ERROR; | |
| } | |
| @@ -673,7 +673,7 @@ static CURLcode tftp_rx(struct tftp_conn *state, tftp_event_t event) | |
| (struct sockaddr *)&state->remote_addr, | |
| state->remote_addrlen); | |
| if(sbytes < 0) { | |
| - | failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | failf(data, "%s", curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| return CURLE_SEND_ERROR; | |
| } | |
| } | |
| @@ -750,8 +750,8 @@ static CURLcode tftp_tx(struct tftp_conn *state, tftp_event_t event) | |
| state->remote_addrlen); | |
| /* Check all sbytes were sent */ | |
| if(sbytes < 0) { | |
| - | failf(data, "%s", Curl_strerror(SOCKERRNO, |
| - | buffer, sizeof(buffer))); |
| + | failf(data, "%s", |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| result = CURLE_SEND_ERROR; | |
| } | |
| } | |
| @@ -795,7 +795,7 @@ static CURLcode tftp_tx(struct tftp_conn *state, tftp_event_t event) | |
| state->remote_addrlen); | |
| /* Check all sbytes were sent */ | |
| if(sbytes < 0) { | |
| - | failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | failf(data, "%s", curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| return CURLE_SEND_ERROR; | |
| } | |
| /* Update the progress meter */ | |
| @@ -821,7 +821,7 @@ static CURLcode tftp_tx(struct tftp_conn *state, tftp_event_t event) | |
| state->remote_addrlen); | |
| /* Check all sbytes were sent */ | |
| if(sbytes < 0) { | |
| - | failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | failf(data, "%s", curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| return CURLE_SEND_ERROR; | |
| } | |
| /* since this was a re-send, we remain at the still byte position */ | |
| @@ -1039,7 +1039,7 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) | |
| if(rc) { | |
| char buffer[STRERROR_LEN]; | |
| failf(data, "bind() failed; %s", | |
| - | Curl_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| + | curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); |
| return CURLE_COULDNT_CONNECT; | |
| } | |
| conn->bits.bound = TRUE; | |
| @@ -1257,7 +1257,7 @@ static CURLcode tftp_multi_statemach(struct Curl_easy *data, bool *done) | |
| /* bail out */ | |
| int error = SOCKERRNO; | |
| char buffer[STRERROR_LEN]; | |
| - | failf(data, "%s", Curl_strerror(error, buffer, sizeof(buffer))); |
| + | failf(data, "%s", curlx_strerror(error, buffer, sizeof(buffer))); |
| state->event = TFTP_EVENT_ERROR; | |
| } | |
| else if(rc) { | |
| @@ -80,7 +80,6 @@ | |
| #include "progress.h" | |
| #include "cookie.h" | |
| #include "strcase.h" | |
| - | #include "strerror.h" |
| #include "escape.h" | |
| #include "share.h" | |
| #include "content_encoding.h" | |
| @@ -125,6 +124,7 @@ | |
| #include "altsvc.h" | |
| #include "curlx/dynbuf.h" | |
| #include "headers.h" | |
| + | #include "curlx/strerr.h" |
| #include "curlx/strparse.h" | |
| /* The last 3 #include files should be in this order */ | |
| #include "curl_printf.h" | |
| @@ -1743,7 +1743,7 @@ static void zonefrom_url(CURLU *uh, struct Curl_easy *data, | |
| #ifndef CURL_DISABLE_VERBOSE_STRINGS | |
| char buffer[STRERROR_LEN]; | |
| infof(data, "Invalid zoneid: %s; %s", zoneid, | |
| - | Curl_strerror(errno, buffer, sizeof(buffer))); |
| + | curlx_strerror(errno, buffer, sizeof(buffer))); |
| #endif | |
| } | |
| else | |
| @@ -1 +0,0 @@ | |
| - | banfunc strerror |
| @@ -1 +0,0 @@ | |
| - | banfunc strerror |
| @@ -57,7 +57,6 @@ | |
| #include "../cf-socket.h" | |
| #include "../connect.h" | |
| #include "../progress.h" | |
| - | #include "../strerror.h" |
| #include "../curlx/dynbuf.h" | |
| #include "../http1.h" | |
| #include "../select.h" | |
| @@ -42,7 +42,6 @@ | |
| #include "../cf-socket.h" | |
| #include "../connect.h" | |
| #include "../progress.h" | |
| - | #include "../strerror.h" |
| #include "../curlx/dynbuf.h" | |
| #include "../http1.h" | |
| #include "../select.h" | |
| @@ -57,6 +56,7 @@ | |
| #include "curl_osslq.h" | |
| #include "../url.h" | |
| #include "../curlx/warnless.h" | |
| + | #include "../curlx/strerr.h" |
| /* The last 3 #include files should be in this order */ | |
| #include "../curl_printf.h" | |
| @@ -552,7 +552,7 @@ static CURLcode cf_osslq_ssl_err(struct Curl_cfilter *cf, | |
| Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip); | |
| if(sockerr && detail == SSL_ERROR_SYSCALL) | |
| - | Curl_strerror(sockerr, extramsg, sizeof(extramsg)); |
| + | curlx_strerror(sockerr, extramsg, sizeof(extramsg)); |
| failf(data, "QUIC connect: %s in connection to %s:%d (%s)", | |
| extramsg[0] ? extramsg : osslq_SSL_ERROR_to_str(detail), | |
| ctx->peer.dispname, ip.remote_port, ip.remote_ip); | |
| @@ -39,7 +39,6 @@ | |
| #include "../multiif.h" | |
| #include "../connect.h" | |
| #include "../progress.h" | |
| - | #include "../strerror.h" |
| #include "../select.h" | |
| #include "../http1.h" | |
| #include "vquic.h" | |
| @@ -43,7 +43,7 @@ | |
| #include "../rand.h" | |
| #include "vquic.h" | |
| #include "vquic_int.h" | |
| - | #include "../strerror.h" |
| + | #include "../curlx/strerr.h" |
| #include "../curlx/strparse.h" | |
| /* The last 3 #include files should be in this order */ | |
| @@ -434,7 +434,7 @@ static CURLcode recvmmsg_packets(struct Curl_cfilter *cf, | |
| result = CURLE_COULDNT_CONNECT; | |
| goto out; | |
| } | |
| - | Curl_strerror(SOCKERRNO, errstr, sizeof(errstr)); |
| + | curlx_strerror(SOCKERRNO, errstr, sizeof(errstr)); |
| failf(data, "QUIC: recvmmsg() unexpectedly returned %d (errno=%d; %s)", | |
| mcount, SOCKERRNO, errstr); | |
| result = CURLE_RECV_ERROR; | |
| @@ -527,7 +527,7 @@ static CURLcode recvmsg_packets(struct Curl_cfilter *cf, | |
| result = CURLE_COULDNT_CONNECT; | |
| goto out; | |
| } | |
| - | Curl_strerror(SOCKERRNO, errstr, sizeof(errstr)); |
| + | curlx_strerror(SOCKERRNO, errstr, sizeof(errstr)); |
| failf(data, "QUIC: recvmsg() unexpectedly returned %zd (errno=%d; %s)", | |
| rc, SOCKERRNO, errstr); | |
| result = CURLE_RECV_ERROR; | |
| @@ -602,7 +602,7 @@ static CURLcode recvfrom_packets(struct Curl_cfilter *cf, | |
| result = CURLE_COULDNT_CONNECT; | |
| goto out; | |
| } | |
| - | Curl_strerror(SOCKERRNO, errstr, sizeof(errstr)); |
| + | curlx_strerror(SOCKERRNO, errstr, sizeof(errstr)); |
| failf(data, "QUIC: recvfrom() unexpectedly returned %zd (errno=%d; %s)", | |
| nread, SOCKERRNO, errstr); | |
| result = CURLE_RECV_ERROR; | |
| @@ -1 +0,0 @@ | |
| - | banfunc strerror |
| @@ -1 +0,0 @@ | |
| - | banfunc strerror |
| @@ -63,9 +63,9 @@ | |
| #include "hostcheck.h" | |
| #include "../transfer.h" | |
| #include "../multiif.h" | |
| + | #include "../curlx/strerr.h" |
| #include "../curlx/strparse.h" | |
| #include "../strdup.h" | |
| - | #include "../strerror.h" |
| #include "../curl_printf.h" | |
| #include "apple.h" | |
| @@ -4668,7 +4668,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, | |
| int sockerr = SOCKERRNO; | |
| if(sockerr && detail == SSL_ERROR_SYSCALL) | |
| - | Curl_strerror(sockerr, extramsg, sizeof(extramsg)); |
| + | curlx_strerror(sockerr, extramsg, sizeof(extramsg)); |
| failf(data, OSSL_PACKAGE " SSL_connect: %s in connection to %s:%d ", | |
| extramsg[0] ? extramsg : SSL_ERROR_to_str(detail), | |
| connssl->peer.hostname, connssl->peer.port); | |
| @@ -5274,7 +5274,7 @@ static CURLcode ossl_send_earlydata(struct Curl_cfilter *cf, | |
| if(sslerror) | |
| ossl_strerror(sslerror, error_buffer, sizeof(error_buffer)); | |
| else if(sockerr) | |
| - | Curl_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| + | curlx_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| else | |
| msnprintf(error_buffer, sizeof(error_buffer), "%s", | |
| SSL_ERROR_to_str(err)); | |
| @@ -5460,7 +5460,7 @@ static CURLcode ossl_send(struct Curl_cfilter *cf, | |
| if(sslerror) | |
| ossl_strerror(sslerror, error_buffer, sizeof(error_buffer)); | |
| else if(sockerr) | |
| - | Curl_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| + | curlx_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| else | |
| msnprintf(error_buffer, sizeof(error_buffer), "%s", | |
| SSL_ERROR_to_str(err)); | |
| @@ -5557,7 +5557,7 @@ static CURLcode ossl_recv(struct Curl_cfilter *cf, | |
| if(sslerror) | |
| ossl_strerror(sslerror, error_buffer, sizeof(error_buffer)); | |
| else if(sockerr && err == SSL_ERROR_SYSCALL) | |
| - | Curl_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| + | curlx_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| else | |
| msnprintf(error_buffer, sizeof(error_buffer), "%s", | |
| SSL_ERROR_to_str(err)); | |
| @@ -5580,7 +5580,7 @@ static CURLcode ossl_recv(struct Curl_cfilter *cf, | |
| * the error in case of some weirdness in the OSSL stack */ | |
| int sockerr = SOCKERRNO; | |
| if(sockerr) | |
| - | Curl_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| + | curlx_strerror(sockerr, error_buffer, sizeof(error_buffer)); |
| else { | |
| msnprintf(error_buffer, sizeof(error_buffer), | |
| "Connection closed abruptly"); | |
| @@ -34,13 +34,13 @@ | |
| #include "../curlx/fopen.h" | |
| #include "../curlx/inet_pton.h" | |
| + | #include "../curlx/strerr.h" |
| #include "../urldata.h" | |
| #include "../sendf.h" | |
| #include "vtls.h" | |
| #include "vtls_int.h" | |
| #include "rustls.h" | |
| #include "keylog.h" | |
| - | #include "../strerror.h" |
| #include "cipher_suite.h" | |
| #include "x509asn1.h" | |
| @@ -171,7 +171,7 @@ static ssize_t tls_recv_more(struct Curl_cfilter *cf, | |
| else if(io_error) { | |
| char buffer[STRERROR_LEN]; | |
| failf(data, "reading from socket: %s", | |
| - | Curl_strerror(io_error, buffer, sizeof(buffer))); |
| + | curlx_strerror(io_error, buffer, sizeof(buffer))); |
| *err = CURLE_RECV_ERROR; | |
| return -1; | |
| } | |
| @@ -283,7 +283,7 @@ static CURLcode cr_flush_out(struct Curl_cfilter *cf, struct Curl_easy *data, | |
| else if(io_error) { | |
| char buffer[STRERROR_LEN]; | |
| failf(data, "writing to socket: %s", | |
| - | Curl_strerror(io_error, buffer, sizeof(buffer))); |
| + | curlx_strerror(io_error, buffer, sizeof(buffer))); |
| return CURLE_SEND_ERROR; | |
| } | |
| if(tlswritten == 0) { | |
| @@ -58,6 +58,7 @@ my %banfunc = ( | |
| "vsnprintf" => 1, | |
| "sscanf" => 1, | |
| "strcat" => 1, | |
| + | "strerror" => 1, |
| "strncat" => 1, | |
| "strncpy" => 1, | |
| "strtok_r" => 1, | |
| @@ -38,12 +38,14 @@ CURLX_CFILES = \ | |
| ../lib/curlx/dynbuf.c \ | |
| ../lib/curlx/fopen.c \ | |
| ../lib/curlx/nonblock.c \ | |
| + | ../lib/curlx/strerr.c \ |
| ../lib/curlx/strparse.c \ | |
| ../lib/curlx/timediff.c \ | |
| ../lib/curlx/timeval.c \ | |
| ../lib/curlx/version_win32.c \ | |
| ../lib/curlx/wait.c \ | |
| - | ../lib/curlx/warnless.c |
| + | ../lib/curlx/warnless.c \ |
| + | ../lib/curlx/winapi.c |
| CURLX_HFILES = \ | |
| ../lib/curlx/binmode.h \ | |
| @@ -52,12 +54,14 @@ CURLX_HFILES = \ | |
| ../lib/curlx/dynbuf.h \ | |
| ../lib/curlx/fopen.h \ | |
| ../lib/curlx/nonblock.h \ | |
| + | ../lib/curlx/strerr.h \ |
| ../lib/curlx/strparse.h \ | |
| ../lib/curlx/timediff.h \ | |
| ../lib/curlx/timeval.h \ | |
| ../lib/curlx/version_win32.h \ | |
| ../lib/curlx/wait.h \ | |
| - | ../lib/curlx/warnless.h |
| + | ../lib/curlx/warnless.h \ |
| + | ../lib/curlx/winapi.h |
| CURL_CFILES = \ | |
| config2setopts.c \ | |
| @@ -83,9 +83,10 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd, | |
| #endif | |
| } | |
| if(result < 0) { | |
| + | char buffer[STRERROR_LEN]; |
| int error = errno; | |
| - | warnf("Setting type of service to %d failed with errno %d: %s", |
| - | tos, error, strerror(error)); |
| + | warnf("Setting type of service to %d failed with errno %d: %s", tos, |
| + | error, curlx_strerror(error, buffer, sizeof(buffer))); |
| } | |
| } | |
| #endif | |
| @@ -94,9 +95,10 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd, | |
| int priority = (int)config->vlan_priority; | |
| if(setsockopt(curlfd, SOL_SOCKET, SO_PRIORITY, | |
| (void *)&priority, sizeof(priority)) != 0) { | |
| + | char buffer[STRERROR_LEN]; |
| int error = errno; | |
| - | warnf("VLAN priority %d failed with errno %d: %s", |
| - | priority, error, strerror(error)); |
| + | warnf("VLAN priority %d failed with errno %d: %s", priority, |
| + | error, curlx_strerror(error, buffer, sizeof(buffer))); |
| } | |
| } | |
| #endif | |
| @@ -96,7 +96,9 @@ bool tool_create_output_file(struct OutStruct *outs, | |
| } | |
| if(!file) { | |
| - | warnf("Failed to open the file %s: %s", fname, strerror(errno)); |
| + | char errbuf[STRERROR_LEN]; |
| + | warnf("Failed to open the file %s: %s", fname, |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| return FALSE; | |
| } | |
| outs->s_isreg = TRUE; | |
| @@ -77,8 +77,11 @@ int getfiletime(const char *filename, curl_off_t *stamp) | |
| *stamp = (curl_off_t)statbuf.st_mtime; | |
| rc = 0; | |
| } | |
| - | else |
| - | warnf("Failed to get filetime: %s", strerror(errno)); |
| + | else { |
| + | char errbuf[STRERROR_LEN]; |
| + | warnf("Failed to get filetime: %s", |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| + | } |
| #endif | |
| return rc; | |
| } | |
| @@ -131,8 +134,10 @@ void setfiletime(curl_off_t filetime, const char *filename) | |
| times[0].tv_sec = times[1].tv_sec = (time_t)filetime; | |
| times[0].tv_usec = times[1].tv_usec = 0; | |
| if(utimes(filename, times)) { | |
| + | char errbuf[STRERROR_LEN]; |
| warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T | |
| - | " on '%s': %s", filetime, filename, strerror(errno)); |
| + | " on '%s': %s", filetime, filename, |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| } | |
| #elif defined(HAVE_UTIME) | |
| @@ -140,8 +145,10 @@ void setfiletime(curl_off_t filetime, const char *filename) | |
| times.actime = (time_t)filetime; | |
| times.modtime = (time_t)filetime; | |
| if(utime(filename, ×)) { | |
| + | char errbuf[STRERROR_LEN]; |
| warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T | |
| - | " on '%s': %s", filetime, filename, strerror(errno)); |
| + | " on '%s': %s", filetime, filename, |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| } | |
| #endif | |
| } | |
| @@ -222,8 +222,9 @@ size_t tool_mime_stdin_read(char *buffer, | |
| /* Read from stdin. */ | |
| nitems = fread(buffer, 1, nitems, stdin); | |
| if(ferror(stdin)) { | |
| + | char errbuf[STRERROR_LEN]; |
| /* Show error only once. */ | |
| - | warnf("stdin: %s", strerror(errno)); |
| + | warnf("stdin: %s", curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| return CURL_READFUNC_ABORT; | |
| } | |
| } | |
| @@ -444,8 +445,9 @@ static int read_field_headers(const char *filename, FILE *fp, | |
| switch(c) { | |
| case EOF: | |
| if(ferror(fp)) { | |
| + | char errbuf[STRERROR_LEN]; |
| errorf("Header file %s read error: %s", filename, | |
| - | strerror(errno)); |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| return -1; | |
| } | |
| return 0; /* Done. */ | |
| @@ -564,9 +566,11 @@ static int get_param_part(char endchar, | |
| sep = *p; | |
| *endpos = '\0'; | |
| fp = curlx_fopen(hdrfile, FOPEN_READTEXT); | |
| - | if(!fp) |
| + | if(!fp) { |
| + | char errbuf[STRERROR_LEN]; |
| warnf("Cannot read from %s: %s", hdrfile, | |
| - | strerror(errno)); |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| + | } |
| else { | |
| int i = read_field_headers(hdrfile, fp, &headers); | |
| @@ -604,9 +604,11 @@ static CURLcode post_per_transfer(struct per_transfer *per, | |
| /* Set file extended attributes */ | |
| if(!result && config->xattr && outs->fopened && outs->stream) { | |
| rc = fwrite_xattr(curl, per->url, fileno(outs->stream)); | |
| - | if(rc) |
| - | warnf("Error setting extended attributes on '%s': %s", |
| - | outs->filename, strerror(errno)); |
| + | if(rc) { |
| + | char errbuf[STRERROR_LEN]; |
| + | warnf("Error setting extended attributes on '%s': %s", outs->filename, |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| + | } |
| } | |
| if(!result && !outs->stream && !outs->bytes) { | |
| @@ -796,9 +798,11 @@ static CURLcode etag_compare(struct OperationConfig *config) | |
| /* open file for reading: */ | |
| FILE *file = curlx_fopen(config->etag_compare_file, FOPEN_READTEXT); | |
| - | if(!file) |
| + | if(!file) { |
| + | char errbuf[STRERROR_LEN]; |
| warnf("Failed to open %s: %s", config->etag_compare_file, | |
| - | strerror(errno)); |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| + | } |
| if((PARAM_OK == file2string(&etag_from_file, file)) && | |
| etag_from_file) { | |
| @@ -1068,8 +1072,11 @@ static void check_stdin_upload(struct OperationConfig *config, | |
| else | |
| per->infd = (int)f; | |
| #endif | |
| - | if(curlx_nonblock((curl_socket_t)per->infd, TRUE) < 0) |
| - | warnf("fcntl failed on fd=%d: %s", per->infd, strerror(errno)); |
| + | if(curlx_nonblock((curl_socket_t)per->infd, TRUE) < 0) { |
| + | char errbuf[STRERROR_LEN]; |
| + | warnf("fcntl failed on fd=%d: %s", per->infd, |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| + | } |
| } | |
| } | |
| @@ -457,7 +457,9 @@ ParameterError setvariable(const char *input) | |
| else { | |
| file = curlx_fopen(line, "rb"); | |
| if(!file) { | |
| - | errorf("Failed to open %s: %s", line, strerror(errno)); |
| + | char errbuf[STRERROR_LEN]; |
| + | errorf("Failed to open %s: %s", line, |
| + | curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| err = PARAM_READ_ERROR; | |
| } | |
| } | |
| @@ -34,14 +34,16 @@ UTILS_C = memptr.c testutil.c testtrace.c | |
| UTILS_H = testutil.h testtrace.h unitcheck.h | |
| CURLX_C = \ | |
| + | ../../lib/curl_threads.c \ |
| ../../lib/curlx/fopen.c \ | |
| - | ../../lib/curlx/warnless.c \ |
| ../../lib/curlx/multibyte.c \ | |
| + | ../../lib/curlx/strerr.c \ |
| ../../lib/curlx/timediff.c \ | |
| ../../lib/curlx/timeval.c \ | |
| - | ../../lib/curl_threads.c \ |
| ../../lib/curlx/version_win32.c \ | |
| - | ../../lib/curlx/wait.c |
| + | ../../lib/curlx/wait.c \ |
| + | ../../lib/curlx/warnless.c \ |
| + | ../../lib/curlx/winapi.c |
| # All libtest programs | |
| TESTS_C = \ | |
| @@ -427,15 +427,17 @@ void ws_close(CURL *curl); | |
| /* ---------------------------------------------------------------- */ | |
| - | #define exe_select_test(A, B, C, D, E, Y, Z) do { \ |
| - | int ec; \ |
| - | if(select_wrapper((A), (B), (C), (D), (E)) == -1) { \ |
| - | ec = SOCKERRNO; \ |
| - | curl_mfprintf(stderr, "%s:%d select() failed, with " \ |
| - | "errno %d (%s)\n", \ |
| - | (Y), (Z), ec, strerror(ec)); \ |
| - | res = TEST_ERR_SELECT; \ |
| - | } \ |
| + | #define exe_select_test(A, B, C, D, E, Y, Z) do { \ |
| + | int ec; \ |
| + | if(select_wrapper((A), (B), (C), (D), (E)) == -1) { \ |
| + | char ecbuf[STRERROR_LEN]; \ |
| + | ec = SOCKERRNO; \ |
| + | curl_mfprintf(stderr, "%s:%d select() failed, with " \ |
| + | "errno %d (%s)\n", \ |
| + | (Y), (Z), \ |
| + | ec, curlx_strerror(ec, ecbuf, sizeof(ecbuf))); \ |
| + | res = TEST_ERR_SELECT; \ |
| + | } \ |
| } while(0) | |
| #define res_select_test(A, B, C, D, E) \ | |
| @@ -36,6 +36,7 @@ static CURLcode test_lib505(const char *URL) | |
| { | |
| CURL *curl; | |
| CURLcode res = CURLE_OK; | |
| + | char errbuf[STRERROR_LEN]; |
| FILE *hd_src; | |
| int hd; | |
| struct_stat file_info; | |
| @@ -54,7 +55,7 @@ static CURLcode test_lib505(const char *URL) | |
| hd_src = curlx_fopen(libtest_arg2, "rb"); | |
| if(!hd_src) { | |
| curl_mfprintf(stderr, "fopen failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| return TEST_ERR_MAJOR_BAD; /* if this happens things are major weird */ | |
| } | |
| @@ -69,7 +70,7 @@ static CURLcode test_lib505(const char *URL) | |
| if(hd == -1) { | |
| /* can't open file, bail out */ | |
| curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| curlx_fclose(hd_src); | |
| return TEST_ERR_MAJOR_BAD; | |
| @@ -51,9 +51,11 @@ static void t518_store_errmsg(const char *msg, int err) | |
| { | |
| if(!err) | |
| curl_msnprintf(t518_msgbuff, sizeof(t518_msgbuff), "%s", msg); | |
| - | else |
| + | else { |
| + | char errbuf[STRERROR_LEN]; |
| curl_msnprintf(t518_msgbuff, sizeof(t518_msgbuff), "%s, errno %d, %s", msg, | |
| - | err, strerror(err)); |
| + | err, curlx_strerror(err, errbuf, sizeof(errbuf))); |
| + | } |
| } | |
| static void t518_close_file_descriptors(void) | |
| @@ -29,6 +29,7 @@ static CURLcode test_lib525(const char *URL) | |
| { | |
| CURLcode res = CURLE_OK; | |
| CURL *curl = NULL; | |
| + | char errbuf[STRERROR_LEN]; |
| FILE *hd_src = NULL; | |
| int hd; | |
| struct_stat file_info; | |
| @@ -45,7 +46,7 @@ static CURLcode test_lib525(const char *URL) | |
| hd_src = curlx_fopen(libtest_arg2, "rb"); | |
| if(!hd_src) { | |
| curl_mfprintf(stderr, "fopen failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| return TEST_ERR_FOPEN; | |
| } | |
| @@ -60,7 +61,7 @@ static CURLcode test_lib525(const char *URL) | |
| if(hd == -1) { | |
| /* can't open file, bail out */ | |
| curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| curlx_fclose(hd_src); | |
| return TEST_ERR_FSTAT; | |
| @@ -48,9 +48,11 @@ static void t537_store_errmsg(const char *msg, int err) | |
| { | |
| if(!err) | |
| curl_msnprintf(t537_msgbuff, sizeof(t537_msgbuff), "%s", msg); | |
| - | else |
| + | else { |
| + | char errbuf[STRERROR_LEN]; |
| curl_msnprintf(t537_msgbuff, sizeof(t537_msgbuff), "%s, errno %d, %s", msg, | |
| - | err, strerror(err)); |
| + | err, curlx_strerror(err, errbuf, sizeof(errbuf))); |
| + | } |
| } | |
| static void t537_close_file_descriptors(void) | |
| @@ -33,6 +33,7 @@ static CURLcode test_lib541(const char *URL) | |
| { | |
| CURL *curl; | |
| CURLcode res = CURLE_OK; | |
| + | char errbuf[STRERROR_LEN]; |
| FILE *hd_src; | |
| int hd; | |
| struct_stat file_info; | |
| @@ -45,7 +46,7 @@ static CURLcode test_lib541(const char *URL) | |
| hd_src = curlx_fopen(libtest_arg2, "rb"); | |
| if(!hd_src) { | |
| curl_mfprintf(stderr, "fopen failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| return TEST_ERR_MAJOR_BAD; /* if this happens things are major weird */ | |
| } | |
| @@ -60,7 +61,7 @@ static CURLcode test_lib541(const char *URL) | |
| if(hd == -1) { | |
| /* can't open file, bail out */ | |
| curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| curlx_fclose(hd_src); | |
| return TEST_ERR_MAJOR_BAD; | |
| @@ -83,8 +83,9 @@ again: | |
| #else | |
| if((size_t)write(STDOUT_FILENO, buf, nread) != nread) { | |
| #endif | |
| + | char errbuf[STRERROR_LEN]; |
| curl_mfprintf(stderr, "write() failed: errno %d (%s)\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| res = TEST_ERR_FAILURE; | |
| break; | |
| } | |
| @@ -225,6 +225,7 @@ static CURLcode test_lib582(const char *URL) | |
| { | |
| CURLcode res = CURLE_OK; | |
| CURL *curl = NULL; | |
| + | char errbuf[STRERROR_LEN]; |
| FILE *hd_src = NULL; | |
| int hd; | |
| struct_stat file_info; | |
| @@ -246,7 +247,7 @@ static CURLcode test_lib582(const char *URL) | |
| hd_src = curlx_fopen(libtest_arg2, "rb"); | |
| if(!hd_src) { | |
| curl_mfprintf(stderr, "fopen() failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| return TEST_ERR_FOPEN; | |
| } | |
| @@ -261,7 +262,7 @@ static CURLcode test_lib582(const char *URL) | |
| if(hd == -1) { | |
| /* can't open file, bail out */ | |
| curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2); | |
| curlx_fclose(hd_src); | |
| return TEST_ERR_FSTAT; | |
| @@ -41,8 +41,9 @@ static CURLcode test_lib591(const char *URL) | |
| upload = curlx_fopen(libtest_arg3, "rb"); | |
| if(!upload) { | |
| + | char errbuf[STRERROR_LEN]; |
| curl_mfprintf(stderr, "fopen() failed with error (%d) %s\n", | |
| - | errno, strerror(errno)); |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg3); | |
| return TEST_ERR_FOPEN; | |
| } | |
| @@ -36,10 +36,11 @@ UTILS_H = | |
| CURLX_C = \ | |
| ../../lib/curlx/base64.c \ | |
| ../../lib/curlx/fopen.c \ | |
| - | ../../lib/curlx/inet_pton.c \ |
| ../../lib/curlx/inet_ntop.c \ | |
| + | ../../lib/curlx/inet_pton.c \ |
| ../../lib/curlx/multibyte.c \ | |
| ../../lib/curlx/nonblock.c \ | |
| + | ../../lib/curlx/strerr.c \ |
| ../../lib/curlx/strparse.c \ | |
| ../../lib/curlx/timediff.c \ | |
| ../../lib/curlx/timeval.c \ | |
| @@ -104,8 +104,10 @@ static int store_incoming(const unsigned char *data, size_t size, | |
| /* Open request dump file. */ | |
| server = fopen(dumpfile, "ab"); | |
| if(!server) { | |
| + | char errbuf[STRERROR_LEN]; |
| int error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Error opening file '%s'", dumpfile); | |
| return -1; | |
| } | |
| @@ -383,6 +385,7 @@ static int test_dnsd(int argc, char **argv) | |
| int flag; | |
| int rc; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int result = 0; | |
| pidname = ".dnsd.pid"; | |
| @@ -480,7 +483,8 @@ static int test_dnsd(int argc, char **argv) | |
| if(CURL_SOCKET_BAD == sock) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error creating socket (%d) %s", error, sstrerror(error)); |
| + | logmsg("Error creating socket (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| result = 1; | |
| goto dnsd_cleanup; | |
| } | |
| @@ -490,7 +494,7 @@ static int test_dnsd(int argc, char **argv) | |
| (void *)&flag, sizeof(flag))) { | |
| error = SOCKERRNO; | |
| logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| result = 1; | |
| goto dnsd_cleanup; | |
| } | |
| @@ -515,8 +519,8 @@ static int test_dnsd(int argc, char **argv) | |
| #endif /* USE_IPV6 */ | |
| if(rc) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error binding socket on port %hu (%d) %s", port, error, |
| - | sstrerror(error)); |
| + | logmsg("Error binding socket on port %hu (%d) %s", port, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| result = 1; | |
| goto dnsd_cleanup; | |
| } | |
| @@ -538,7 +542,7 @@ static int test_dnsd(int argc, char **argv) | |
| if(getsockname(sock, &localaddr.sa, &la_size) < 0) { | |
| error = SOCKERRNO; | |
| logmsg("getsockname() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| goto dnsd_cleanup; | |
| } | |
| @@ -130,7 +130,6 @@ extern void logmsg(const char *msg, ...); | |
| extern void loghex(unsigned char *buffer, ssize_t len); | |
| extern unsigned char byteval(char *value); | |
| extern int win32_init(void); | |
| - | extern const char *sstrerror(int err); |
| extern FILE *test2fopen(long testno, const char *logdir2); | |
| extern curl_off_t our_getpid(void); | |
| extern int write_pidfile(const char *filename); | |
| @@ -557,8 +557,10 @@ static curl_socket_t mqttit(curl_socket_t fd) | |
| logmsg("SUBSCRIBE to '%s' [%d]", topic, packet_id); | |
| stream = test2fopen(testno, logdir); | |
| if(!stream) { | |
| + | char errbuf[STRERROR_LEN]; |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Couldn't open test file %ld", testno); | |
| goto end; | |
| } | |
| @@ -658,6 +660,7 @@ static bool mqttd_incoming(curl_socket_t listenfd) | |
| do { | |
| ssize_t rc; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| curl_socket_t sockfd = listenfd; | |
| int maxfd = (int)sockfd; | |
| @@ -686,7 +689,7 @@ static bool mqttd_incoming(curl_socket_t listenfd) | |
| if(rc < 0) { | |
| logmsg("select() failed with error (%d) %s", | |
| - | error, strerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return FALSE; | |
| } | |
| @@ -694,7 +697,8 @@ static bool mqttd_incoming(curl_socket_t listenfd) | |
| curl_socket_t newfd = accept(sockfd, NULL, NULL); | |
| if(CURL_SOCKET_BAD == newfd) { | |
| error = SOCKERRNO; | |
| - | logmsg("accept() failed with error (%d) %s", error, sstrerror(error)); |
| + | logmsg("accept() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| } | |
| else { | |
| logmsg("====> Client connect, fd %ld. " | |
| @@ -720,6 +724,7 @@ static int test_mqttd(int argc, char *argv[]) | |
| int wroteportfile = 0; | |
| bool juggle_again; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int arg = 1; | |
| pidname = ".mqttd.pid"; | |
| @@ -825,7 +830,8 @@ static int test_mqttd(int argc, char *argv[]) | |
| if(CURL_SOCKET_BAD == sock) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error creating socket (%d) %s", error, sstrerror(error)); |
| + | logmsg("Error creating socket (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto mqttd_cleanup; | |
| } | |
| @@ -225,8 +225,10 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) | |
| stream = test2fopen(req->testno, logdir); | |
| if(!stream) { | |
| + | char errbuf[STRERROR_LEN]; |
| int error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Couldn't open test file %ld", req->testno); | |
| req->open = FALSE; /* closes connection */ | |
| return 1; /* done */ | |
| @@ -527,6 +529,7 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize) | |
| { | |
| int res; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| size_t written; | |
| size_t writeleft; | |
| FILE *dump; | |
| @@ -544,8 +547,8 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize) | |
| /* !checksrc! disable ERRNOVAR 1 */ | |
| } while(!dump && ((error = errno) == EINTR)); | |
| if(!dump) { | |
| - | logmsg("Error opening file %s error (%d) %s", |
| - | dumpfile, error, strerror(error)); |
| + | logmsg("Error opening file %s error (%d) %s", dumpfile, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Failed to write request input to %s", dumpfile); | |
| return; | |
| } | |
| @@ -564,8 +567,8 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize) | |
| if(writeleft == 0) | |
| logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile); | |
| else if(writeleft > 0) { | |
| - | logmsg("Error writing file %s error (%d) %s", |
| - | dumpfile, error, strerror(error)); |
| + | logmsg("Error writing file %s error (%d) %s", dumpfile, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Wrote only (%zu bytes) of (%zu bytes) request input to %s", | |
| totalsize-writeleft, totalsize, dumpfile); | |
| } | |
| @@ -574,14 +577,15 @@ storerequest_cleanup: | |
| res = fclose(dump); | |
| if(res) | |
| - | logmsg("Error closing file %s error (%d) %s", |
| - | dumpfile, errno, strerror(errno)); |
| + | logmsg("Error closing file %s error (%d) %s", dumpfile, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| } | |
| /* return 0 on success, non-zero on failure */ | |
| static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req) | |
| { | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int fail = 0; | |
| int done_processing = 0; | |
| char *reqbuf = req->reqbuf; | |
| @@ -642,7 +646,8 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req) | |
| } | |
| else if(got < 0) { | |
| error = SOCKERRNO; | |
| - | logmsg("recv() returned error (%d) %s", error, sstrerror(error)); |
| + | logmsg("recv() returned error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| fail = 1; | |
| } | |
| if(fail) { | |
| @@ -704,6 +709,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) | |
| bool sendfailure = FALSE; | |
| size_t responsesize; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| int res; | |
| static char weare[256]; | |
| char responsedump[256]; | |
| @@ -788,7 +794,8 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) | |
| snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno); | |
| if(!stream) { | |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Couldn't open test file"); | |
| return 0; | |
| } | |
| @@ -811,7 +818,8 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) | |
| stream = test2fopen(req->testno, logdir); | |
| if(!stream) { | |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Couldn't open test file"); | |
| free(ptr); | |
| return 0; | |
| @@ -851,7 +859,8 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) | |
| dump = fopen(responsedump, "ab"); | |
| if(!dump) { | |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Error opening file '%s'", responsedump); | |
| logmsg("couldn't create logfile '%s'", responsedump); | |
| free(ptr); | |
| @@ -907,8 +916,8 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) | |
| res = fclose(dump); | |
| if(res) | |
| - | logmsg("Error closing file %s error (%d) %s", |
| - | responsedump, errno, strerror(errno)); |
| + | logmsg("Error closing file %s error (%d) %s", responsedump, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| if(got_exit_signal) { | |
| free(ptr); | |
| @@ -948,7 +957,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) | |
| /* should not happen */ | |
| error = SOCKERRNO; | |
| logmsg("curlx_wait_ms() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| break; | |
| } | |
| } | |
| @@ -987,6 +996,7 @@ static int test_rtspd(int argc, char *argv[]) | |
| struct rtspd_httprequest req; | |
| int rc; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int arg = 1; | |
| memset(&req, 0, sizeof(req)); | |
| @@ -1092,7 +1102,8 @@ static int test_rtspd(int argc, char *argv[]) | |
| if(CURL_SOCKET_BAD == sock) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error creating socket (%d) %s", error, sstrerror(error)); |
| + | logmsg("Error creating socket (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto server_cleanup; | |
| } | |
| @@ -1101,7 +1112,7 @@ static int test_rtspd(int argc, char *argv[]) | |
| (void *)&flag, sizeof(flag))) { | |
| error = SOCKERRNO; | |
| logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto server_cleanup; | |
| } | |
| @@ -1125,8 +1136,8 @@ static int test_rtspd(int argc, char *argv[]) | |
| #endif /* USE_IPV6 */ | |
| if(rc) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error binding socket on port %hu (%d) %s", |
| - | port, error, sstrerror(error)); |
| + | logmsg("Error binding socket on port %hu (%d) %s", port, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto server_cleanup; | |
| } | |
| @@ -1147,7 +1158,7 @@ static int test_rtspd(int argc, char *argv[]) | |
| if(getsockname(sock, &localaddr.sa, &la_size) < 0) { | |
| error = SOCKERRNO; | |
| logmsg("getsockname() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| goto server_cleanup; | |
| } | |
| @@ -1180,7 +1191,7 @@ static int test_rtspd(int argc, char *argv[]) | |
| if(rc) { | |
| error = SOCKERRNO; | |
| logmsg("listen() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto server_cleanup; | |
| } | |
| @@ -1207,7 +1218,7 @@ static int test_rtspd(int argc, char *argv[]) | |
| if(CURL_SOCKET_BAD == msgsock) { | |
| error = SOCKERRNO; | |
| logmsg("MAJOR ERROR, accept() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| break; | |
| } | |
| @@ -200,6 +200,7 @@ static ssize_t fullread(int filedes, void *buffer, size_t nbytes) | |
| } | |
| if(rc < 0) { | |
| + | char errbuf[STRERROR_LEN]; |
| error = errno; | |
| /* !checksrc! disable ERRNOVAR 1 */ | |
| if((error == EINTR) || (error == EAGAIN)) | |
| @@ -211,7 +212,7 @@ static ssize_t fullread(int filedes, void *buffer, size_t nbytes) | |
| } | |
| logmsg("reading from file descriptor: %d,", filedes); | |
| logmsg("unrecoverable read() failure (%d) %s", | |
| - | error, strerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return -1; | |
| } | |
| @@ -253,13 +254,14 @@ static ssize_t fullwrite(int filedes, const void *buffer, size_t nbytes) | |
| } | |
| if(wc < 0) { | |
| + | char errbuf[STRERROR_LEN]; |
| error = errno; | |
| /* !checksrc! disable ERRNOVAR 1 */ | |
| if((error == EINTR) || (error == EAGAIN)) | |
| continue; | |
| logmsg("writing to file descriptor: %d,", filedes); | |
| logmsg("unrecoverable write() failure (%d) %s", | |
| - | error, strerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return -1; | |
| } | |
| @@ -947,6 +949,7 @@ static bool juggle(curl_socket_t *sockfdp, | |
| int maxfd = -99; | |
| ssize_t rc; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| unsigned char buffer[BUFFER_SIZE]; | |
| char data[16]; | |
| @@ -1067,7 +1070,7 @@ static bool juggle(curl_socket_t *sockfdp, | |
| if(rc < 0) { | |
| logmsg("select() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return FALSE; | |
| } | |
| @@ -1172,7 +1175,8 @@ static bool juggle(curl_socket_t *sockfdp, | |
| curl_socket_t newfd = accept(sockfd, NULL, NULL); | |
| if(CURL_SOCKET_BAD == newfd) { | |
| error = SOCKERRNO; | |
| - | logmsg("accept() failed with error (%d) %s", error, sstrerror(error)); |
| + | logmsg("accept() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| } | |
| else { | |
| logmsg("====> Client connect"); | |
| @@ -1226,6 +1230,7 @@ static int test_sockfilt(int argc, char *argv[]) | |
| bool juggle_again; | |
| int rc; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int arg = 1; | |
| enum sockmode mode = PASSIVE_LISTEN; /* default */ | |
| const char *addr = NULL; | |
| @@ -1345,7 +1350,8 @@ static int test_sockfilt(int argc, char *argv[]) | |
| if(CURL_SOCKET_BAD == sock) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error creating socket (%d) %s", error, sstrerror(error)); |
| + | logmsg("Error creating socket (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| write_stdout("FAIL\n", 5); | |
| goto sockfilt_cleanup; | |
| } | |
| @@ -1382,8 +1388,8 @@ static int test_sockfilt(int argc, char *argv[]) | |
| } | |
| if(rc) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error connecting to port %hu (%d) %s", |
| - | server_connectport, error, sstrerror(error)); |
| + | logmsg("Error connecting to port %hu (%d) %s", server_connectport, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| write_stdout("FAIL\n", 5); | |
| goto sockfilt_cleanup; | |
| } | |
| @@ -209,9 +209,10 @@ static curl_socket_t socksconnect(unsigned short connectport, | |
| rc = connect(sock, &me.sa, sizeof(me.sa4)); | |
| if(rc) { | |
| + | char errbuf[STRERROR_LEN]; |
| int error = SOCKERRNO; | |
| - | logmsg("Failed connecting to %s:%hu (%d) %s", |
| - | connectaddr, connectport, error, sstrerror(error)); |
| + | logmsg("Failed connecting to %s:%hu (%d) %s", connectaddr, connectport, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return CURL_SOCKET_BAD; | |
| } | |
| logmsg("Connected fine to %s:%d", connectaddr, connectport); | |
| @@ -621,6 +622,7 @@ static bool socksd_incoming(curl_socket_t listenfd) | |
| int i; | |
| ssize_t rc; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| curl_socket_t sockfd = listenfd; | |
| int maxfd = (int)sockfd; | |
| @@ -676,7 +678,7 @@ static bool socksd_incoming(curl_socket_t listenfd) | |
| if(rc < 0) { | |
| logmsg("select() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return FALSE; | |
| } | |
| @@ -685,7 +687,7 @@ static bool socksd_incoming(curl_socket_t listenfd) | |
| if(CURL_SOCKET_BAD == newfd) { | |
| error = SOCKERRNO; | |
| logmsg("accept() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| } | |
| else { | |
| curl_socket_t remotefd; | |
| @@ -738,6 +740,7 @@ static int test_socksd(int argc, char *argv[]) | |
| int wroteportfile = 0; | |
| bool juggle_again; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int arg = 1; | |
| const char *unix_socket = NULL; | |
| @@ -870,7 +873,7 @@ static int test_socksd(int argc, char *argv[]) | |
| if(CURL_SOCKET_BAD == sock) { | |
| error = SOCKERRNO; | |
| logmsg("Error creating socket (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto socks5_cleanup; | |
| } | |
| @@ -922,7 +925,8 @@ socks5_cleanup: | |
| #ifdef USE_UNIX_SOCKETS | |
| if(unlink_socket && socket_domain == AF_UNIX && unix_socket) { | |
| error = unlink(unix_socket); | |
| - | logmsg("unlink(%s) = %d (%s)", unix_socket, error, strerror(error)); |
| + | logmsg("unlink(%s) = %d (%s)", unix_socket, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| } | |
| #endif | |
| @@ -204,8 +204,10 @@ static int sws_parse_servercmd(struct sws_httprequest *req) | |
| req->connmon = FALSE; | |
| if(!stream) { | |
| + | char errbuf[STRERROR_LEN]; |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg(" Couldn't open test file %ld", req->testno); | |
| req->open = FALSE; /* closes connection */ | |
| return 1; /* done */ | |
| @@ -706,6 +708,7 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize) | |
| { | |
| int res; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| size_t written; | |
| size_t writeleft; | |
| FILE *dump; | |
| @@ -724,8 +727,8 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize) | |
| /* !checksrc! disable ERRNOVAR 1 */ | |
| } while(!dump && ((error = errno) == EINTR)); | |
| if(!dump) { | |
| - | logmsg("[2] Error opening file %s error (%d) %s", |
| - | dumpfile, error, strerror(error)); |
| + | logmsg("[2] Error opening file %s error (%d) %s", dumpfile, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Failed to write request input "); | |
| return; | |
| } | |
| @@ -744,8 +747,8 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize) | |
| if(writeleft == 0) | |
| logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile); | |
| else if(writeleft > 0) { | |
| - | logmsg("Error writing file %s error (%d) %s", |
| - | dumpfile, error, strerror(error)); |
| + | logmsg("Error writing file %s error (%d) %s", dumpfile, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Wrote only (%zu bytes) of (%zu bytes) request input to %s", | |
| totalsize-writeleft, totalsize, dumpfile); | |
| } | |
| @@ -754,8 +757,8 @@ storerequest_cleanup: | |
| res = fclose(dump); | |
| if(res) | |
| - | logmsg("Error closing file %s error (%d) %s", |
| - | dumpfile, errno, strerror(errno)); |
| + | logmsg("Error closing file %s error (%d) %s", dumpfile, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| } | |
| static void init_httprequest(struct sws_httprequest *req) | |
| @@ -883,12 +886,14 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req) | |
| fail = 1; | |
| } | |
| else if(got < 0) { | |
| + | char errbuf[STRERROR_LEN]; |
| int error = SOCKERRNO; | |
| if(EAGAIN == error || SOCKEWOULDBLOCK == error) { | |
| /* nothing to read at the moment */ | |
| return 0; | |
| } | |
| - | logmsg("recv() returned error (%d) %s", error, sstrerror(error)); |
| + | logmsg("recv() returned error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| fail = 1; | |
| } | |
| if(fail) { | |
| @@ -947,6 +952,7 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) | |
| bool sendfailure = FALSE; | |
| size_t responsesize; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| int res; | |
| static char weare[256]; | |
| char responsedump[256]; | |
| @@ -1027,7 +1033,8 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) | |
| stream = test2fopen(req->testno, logdir); | |
| if(!stream) { | |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return 0; | |
| } | |
| else { | |
| @@ -1049,7 +1056,8 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) | |
| stream = test2fopen(req->testno, logdir); | |
| if(!stream) { | |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| free(ptr); | |
| return 0; | |
| } | |
| @@ -1088,7 +1096,8 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) | |
| dump = fopen(responsedump, "ab"); | |
| if(!dump) { | |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg(" [5] Error opening file '%s'", responsedump); | |
| free(ptr); | |
| free(cmd); | |
| @@ -1140,8 +1149,8 @@ retry: | |
| res = fclose(dump); | |
| if(res) | |
| - | logmsg("Error closing file %s error (%d) %s", |
| - | responsedump, errno, strerror(errno)); |
| + | logmsg("Error closing file %s error (%d) %s", responsedump, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| if(got_exit_signal) { | |
| free(ptr); | |
| @@ -1181,7 +1190,7 @@ retry: | |
| /* should not happen */ | |
| error = SOCKERRNO; | |
| logmsg("curlx_wait_ms() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| break; | |
| } | |
| } | |
| @@ -1212,6 +1221,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) | |
| srvr_sockaddr_union_t serveraddr; | |
| curl_socket_t serverfd; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int rc = 0; | |
| const char *op_br = ""; | |
| const char *cl_br = ""; | |
| @@ -1234,7 +1244,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) | |
| if(CURL_SOCKET_BAD == serverfd) { | |
| error = SOCKERRNO; | |
| logmsg("Error creating socket for server connection (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -1254,7 +1264,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) | |
| if(curlx_nonblock(serverfd, TRUE)) { | |
| error = SOCKERRNO; | |
| logmsg("curlx_nonblock(TRUE) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(serverfd); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -1336,8 +1346,8 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port) | |
| } | |
| } | |
| error: | |
| - | logmsg("Error connecting to server port %hu (%d) %s", |
| - | port, error, sstrerror(error)); |
| + | logmsg("Error connecting to server port %hu (%d) %s", port, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(serverfd); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -1348,7 +1358,7 @@ success: | |
| if(curlx_nonblock(serverfd, FALSE)) { | |
| error = SOCKERRNO; | |
| logmsg("curlx_nonblock(FALSE) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(serverfd); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -1812,6 +1822,7 @@ static curl_socket_t accept_connection(curl_socket_t sock) | |
| { | |
| curl_socket_t msgsock = CURL_SOCKET_BAD; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int flag = 1; | |
| if(MAX_SOCKETS == num_sockets) { | |
| @@ -1834,14 +1845,14 @@ static curl_socket_t accept_connection(curl_socket_t sock) | |
| return 0; | |
| } | |
| logmsg("MAJOR ERROR, accept() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return CURL_SOCKET_BAD; | |
| } | |
| if(curlx_nonblock(msgsock, TRUE)) { | |
| error = SOCKERRNO; | |
| logmsg("curlx_nonblock failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(msgsock); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -1850,7 +1861,7 @@ static curl_socket_t accept_connection(curl_socket_t sock) | |
| (void *)&flag, sizeof(flag))) { | |
| error = SOCKERRNO; | |
| logmsg("setsockopt(SO_KEEPALIVE) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(msgsock); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -1977,6 +1988,7 @@ static int test_sws(int argc, char *argv[]) | |
| struct sws_httprequest *req = NULL; | |
| int rc = 0; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int arg = 1; | |
| const char *connecthost = "127.0.0.1"; | |
| char port_str[11]; | |
| @@ -2152,7 +2164,8 @@ static int test_sws(int argc, char *argv[]) | |
| if(CURL_SOCKET_BAD == sock) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error creating socket (%d) %s", error, sstrerror(error)); |
| + | logmsg("Error creating socket (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto sws_cleanup; | |
| } | |
| @@ -2161,13 +2174,13 @@ static int test_sws(int argc, char *argv[]) | |
| (void *)&flag, sizeof(flag))) { | |
| error = SOCKERRNO; | |
| logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto sws_cleanup; | |
| } | |
| if(curlx_nonblock(sock, TRUE)) { | |
| error = SOCKERRNO; | |
| logmsg("curlx_nonblock failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto sws_cleanup; | |
| } | |
| @@ -2197,12 +2210,12 @@ static int test_sws(int argc, char *argv[]) | |
| error = SOCKERRNO; | |
| #ifdef USE_UNIX_SOCKETS | |
| if(socket_domain == AF_UNIX) | |
| - | logmsg("Error binding socket on path %s (%d) %s", |
| - | unix_socket, error, sstrerror(error)); |
| + | logmsg("Error binding socket on path %s (%d) %s", unix_socket, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| else | |
| #endif | |
| - | logmsg("Error binding socket on port %hu (%d) %s", |
| - | port, error, sstrerror(error)); |
| + | logmsg("Error binding socket on port %hu (%d) %s", port, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto sws_cleanup; | |
| } | |
| @@ -2223,7 +2236,7 @@ static int test_sws(int argc, char *argv[]) | |
| if(getsockname(sock, &localaddr.sa, &la_size) < 0) { | |
| error = SOCKERRNO; | |
| logmsg("getsockname() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| goto sws_cleanup; | |
| } | |
| @@ -2261,7 +2274,8 @@ static int test_sws(int argc, char *argv[]) | |
| rc = listen(sock, 50); | |
| if(rc) { | |
| error = SOCKERRNO; | |
| - | logmsg("listen() failed with error (%d) %s", error, sstrerror(error)); |
| + | logmsg("listen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto sws_cleanup; | |
| } | |
| @@ -2341,7 +2355,8 @@ static int test_sws(int argc, char *argv[]) | |
| if(rc < 0) { | |
| error = SOCKERRNO; | |
| - | logmsg("select() failed with error (%d) %s", error, sstrerror(error)); |
| + | logmsg("select() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| goto sws_cleanup; | |
| } | |
| @@ -2446,7 +2461,8 @@ sws_cleanup: | |
| #ifdef USE_UNIX_SOCKETS | |
| if(unlink_socket && socket_domain == AF_UNIX && unix_socket) { | |
| rc = unlink(unix_socket); | |
| - | logmsg("unlink(%s) = %d (%s)", unix_socket, rc, strerror(rc)); |
| + | logmsg("unlink(%s) = %d (%s)", unix_socket, |
| + | rc, curlx_strerror(rc, errbuf, sizeof(errbuf))); |
| } | |
| #endif | |
| @@ -130,7 +130,7 @@ struct formats { | |
| struct errmsg { | |
| int e_code; | |
| - | const char *e_msg; |
| + | char e_msg[STRERROR_LEN]; |
| }; | |
| typedef union { | |
| @@ -174,7 +174,7 @@ static struct errmsg errmsgs[] = { | |
| { TFTP_EBADID, "Unknown transfer ID" }, | |
| { TFTP_EEXISTS, "File already exists" }, | |
| { TFTP_ENOUSER, "No such user" }, | |
| - | { -1, 0 } |
| + | { -1, "" } |
| }; | |
| static const struct formats formata[] = { | |
| @@ -548,6 +548,7 @@ static int test_tftpd(int argc, char **argv) | |
| int flag; | |
| int rc; | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| struct testcase test; | |
| int result = 0; | |
| srvr_sockaddr_union_t from; | |
| @@ -654,7 +655,8 @@ static int test_tftpd(int argc, char **argv) | |
| if(CURL_SOCKET_BAD == sock) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error creating socket (%d) %s", error, sstrerror(error)); |
| + | logmsg("Error creating socket (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| result = 1; | |
| goto tftpd_cleanup; | |
| } | |
| @@ -664,7 +666,7 @@ static int test_tftpd(int argc, char **argv) | |
| (void *)&flag, sizeof(flag))) { | |
| error = SOCKERRNO; | |
| logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| result = 1; | |
| goto tftpd_cleanup; | |
| } | |
| @@ -689,8 +691,8 @@ static int test_tftpd(int argc, char **argv) | |
| #endif /* USE_IPV6 */ | |
| if(rc) { | |
| error = SOCKERRNO; | |
| - | logmsg("Error binding socket on port %hu (%d) %s", port, error, |
| - | sstrerror(error)); |
| + | logmsg("Error binding socket on port %hu (%d) %s", port, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| result = 1; | |
| goto tftpd_cleanup; | |
| } | |
| @@ -712,7 +714,7 @@ static int test_tftpd(int argc, char **argv) | |
| if(getsockname(sock, &localaddr.sa, &la_size) < 0) { | |
| error = SOCKERRNO; | |
| logmsg("getsockname() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| goto tftpd_cleanup; | |
| } | |
| @@ -898,8 +900,10 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) | |
| /* Open request dump file. */ | |
| server = fopen(dumpfile, "ab"); | |
| if(!server) { | |
| + | char errbuf[STRERROR_LEN]; |
| int error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Error opening file '%s'", dumpfile); | |
| return -1; | |
| } | |
| @@ -1005,8 +1009,10 @@ static int tftpd_parse_servercmd(struct testcase *req) | |
| stream = test2fopen(req->testno, logdir); | |
| if(!stream) { | |
| + | char errbuf[STRERROR_LEN]; |
| error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg(" Couldn't open test file %ld", req->testno); | |
| return 1; /* done */ | |
| } | |
| @@ -1107,7 +1113,6 @@ static int validate_access(struct testcase *test, | |
| else | |
| partno = 0; | |
| - | |
| logmsg("requested test number %ld part %ld", testno, partno); | |
| test->testno = testno; | |
| @@ -1120,8 +1125,10 @@ static int validate_access(struct testcase *test, | |
| snprintf(partbuf, sizeof(partbuf), "data%ld", partno); | |
| if(!stream) { | |
| + | char errbuf[STRERROR_LEN]; |
| int error = errno; | |
| - | logmsg("fopen() failed with error (%d) %s", error, strerror(error)); |
| + | logmsg("fopen() failed with error (%d) %s", |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Couldn't open test file for test: %ld", testno); | |
| return TFTP_EACCESS; | |
| } | |
| @@ -1356,7 +1363,7 @@ static void nak(int error) | |
| if(pe->e_code == error) | |
| break; | |
| if(pe->e_code < 0) { | |
| - | pe->e_msg = strerror(error - 100); |
| + | curlx_strerror(error - 100, pe->e_msg, sizeof(pe->e_msg)); |
| tp->th_code = TFTP_EUNDEF; /* set 'undef' errorcode */ | |
| } | |
| length = (int)strlen(pe->e_msg); | |
| @@ -123,9 +123,10 @@ void logmsg(const char *msg, ...) | |
| fclose(logfp); | |
| } | |
| else { | |
| + | char errbuf[STRERROR_LEN]; |
| int error = errno; | |
| fprintf(stderr, "fopen() failed with error (%d) %s\n", | |
| - | error, strerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| fprintf(stderr, "Error opening file '%s'\n", serverlogfile); | |
| fprintf(stderr, "Msg not logged: %s %s\n", timebuf, buffer); | |
| } | |
| @@ -189,15 +190,6 @@ int win32_init(void) | |
| atexit(win32_cleanup); | |
| return 0; | |
| } | |
| - | |
| - | /* socket-safe strerror (works on Winsock errors, too) */ |
| - | const char *sstrerror(int err) |
| - | { |
| - | static char buf[512]; |
| - | return curlx_winapi_strerror(err, buf, sizeof(buf)); |
| - | } |
| - | #else |
| - | #define sstrerror(e) strerror(e) |
| #endif /* _WIN32 */ | |
| /* fopens the test case file */ | |
| @@ -246,7 +238,9 @@ int write_pidfile(const char *filename) | |
| pid = our_getpid(); | |
| pidfile = fopen(filename, "wb"); | |
| if(!pidfile) { | |
| - | logmsg("Couldn't write pid file: %s %s", filename, strerror(errno)); |
| + | char errbuf[STRERROR_LEN]; |
| + | logmsg("Couldn't write pid file: %s (%d) %s", filename, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| return 0; /* fail */ | |
| } | |
| fprintf(pidfile, "%ld\n", (long)pid); | |
| @@ -260,7 +254,9 @@ int write_portfile(const char *filename, int port) | |
| { | |
| FILE *portfile = fopen(filename, "wb"); | |
| if(!portfile) { | |
| - | logmsg("Couldn't write port file: %s %s", filename, strerror(errno)); |
| + | char errbuf[STRERROR_LEN]; |
| + | logmsg("Couldn't write port file: %s (%d) %s", filename, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| return 0; /* fail */ | |
| } | |
| fprintf(portfile, "%d\n", port); | |
| @@ -273,6 +269,7 @@ void set_advisor_read_lock(const char *filename) | |
| { | |
| FILE *lockfile; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| int res; | |
| do { | |
| @@ -280,15 +277,15 @@ void set_advisor_read_lock(const char *filename) | |
| /* !checksrc! disable ERRNOVAR 1 */ | |
| } while(!lockfile && ((error = errno) == EINTR)); | |
| if(!lockfile) { | |
| - | logmsg("Error creating lock file %s error (%d) %s", |
| - | filename, error, strerror(error)); |
| + | logmsg("Error creating lock file %s error (%d) %s", filename, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return; | |
| } | |
| res = fclose(lockfile); | |
| if(res) | |
| - | logmsg("Error closing lock file %s error (%d) %s", |
| - | filename, errno, strerror(errno)); |
| + | logmsg("Error closing lock file %s error (%d) %s", filename, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| } | |
| void clear_advisor_read_lock(const char *filename) | |
| @@ -306,9 +303,11 @@ void clear_advisor_read_lock(const char *filename) | |
| res = unlink(filename); | |
| /* !checksrc! disable ERRNOVAR 1 */ | |
| } while(res && ((error = errno) == EINTR)); | |
| - | if(res) |
| - | logmsg("Error removing lock file %s error (%d) %s", |
| - | filename, error, strerror(error)); |
| + | if(res) { |
| + | char errbuf[STRERROR_LEN]; |
| + | logmsg("Error removing lock file %s error (%d) %s", filename, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| + | } |
| } | |
| /* vars used to keep around previous signal handlers */ | |
| @@ -566,6 +565,8 @@ static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler, | |
| void install_signal_handlers(bool keep_sigalrm) | |
| { | |
| + | char errbuf[STRERROR_LEN]; |
| + | (void)errbuf; |
| #ifdef _WIN32 | |
| /* setup Windows exit event before any signal can trigger */ | |
| exit_event = CreateEvent(NULL, TRUE, FALSE, NULL); | |
| @@ -576,20 +577,23 @@ void install_signal_handlers(bool keep_sigalrm) | |
| /* ignore SIGHUP signal */ | |
| old_sighup_handler = set_signal(SIGHUP, SIG_IGN, FALSE); | |
| if(old_sighup_handler == SIG_ERR) | |
| - | logmsg("cannot install SIGHUP handler: %s", strerror(errno)); |
| + | logmsg("cannot install SIGHUP handler: (%d) %s", |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| #endif | |
| #ifdef SIGPIPE | |
| /* ignore SIGPIPE signal */ | |
| old_sigpipe_handler = set_signal(SIGPIPE, SIG_IGN, FALSE); | |
| if(old_sigpipe_handler == SIG_ERR) | |
| - | logmsg("cannot install SIGPIPE handler: %s", strerror(errno)); |
| + | logmsg("cannot install SIGPIPE handler: (%d) %s", |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| #endif | |
| #ifdef SIGALRM | |
| if(!keep_sigalrm) { | |
| /* ignore SIGALRM signal */ | |
| old_sigalrm_handler = set_signal(SIGALRM, SIG_IGN, FALSE); | |
| if(old_sigalrm_handler == SIG_ERR) | |
| - | logmsg("cannot install SIGALRM handler: %s", strerror(errno)); |
| + | logmsg("cannot install SIGALRM handler: (%d) %s", |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| } | |
| #else | |
| (void)keep_sigalrm; | |
| @@ -598,19 +602,22 @@ void install_signal_handlers(bool keep_sigalrm) | |
| /* handle SIGINT signal with our exit_signal_handler */ | |
| old_sigint_handler = set_signal(SIGINT, exit_signal_handler, TRUE); | |
| if(old_sigint_handler == SIG_ERR) | |
| - | logmsg("cannot install SIGINT handler: %s", strerror(errno)); |
| + | logmsg("cannot install SIGINT handler: (%d) %s", |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| #endif | |
| #ifdef SIGTERM | |
| /* handle SIGTERM signal with our exit_signal_handler */ | |
| old_sigterm_handler = set_signal(SIGTERM, exit_signal_handler, TRUE); | |
| if(old_sigterm_handler == SIG_ERR) | |
| - | logmsg("cannot install SIGTERM handler: %s", strerror(errno)); |
| + | logmsg("cannot install SIGTERM handler: (%d) %s", |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| #endif | |
| #if defined(SIGBREAK) && defined(_WIN32) | |
| /* handle SIGBREAK signal with our exit_signal_handler */ | |
| old_sigbreak_handler = set_signal(SIGBREAK, exit_signal_handler, TRUE); | |
| if(old_sigbreak_handler == SIG_ERR) | |
| - | logmsg("cannot install SIGBREAK handler: %s", strerror(errno)); |
| + | logmsg("cannot install SIGBREAK handler: (%d) %s", |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| #endif | |
| #ifdef _WIN32 | |
| #ifndef UNDER_CE | |
| @@ -687,6 +694,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, | |
| struct sockaddr_un *sau) | |
| { | |
| int error; | |
| + | char errbuf[STRERROR_LEN]; |
| int rc; | |
| size_t len = strlen(unix_socket); | |
| @@ -703,8 +711,8 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, | |
| /* socket already exists. Perhaps it is stale? */ | |
| curl_socket_t unixfd = socket(AF_UNIX, SOCK_STREAM, 0); | |
| if(CURL_SOCKET_BAD == unixfd) { | |
| - | logmsg("Failed to create socket at %s (%d) %s", |
| - | unix_socket, SOCKERRNO, sstrerror(SOCKERRNO)); |
| + | logmsg("Failed to create socket at %s (%d) %s", unix_socket, |
| + | SOCKERRNO, curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf))); |
| return -1; | |
| } | |
| /* check whether the server is alive */ | |
| @@ -712,8 +720,8 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, | |
| error = SOCKERRNO; | |
| sclose(unixfd); | |
| if(rc && error != SOCKECONNREFUSED) { | |
| - | logmsg("Failed to connect to %s (%d) %s", |
| - | unix_socket, error, sstrerror(error)); |
| + | logmsg("Failed to connect to %s (%d) %s", unix_socket, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| return rc; | |
| } | |
| /* socket server is not alive, now check if it was actually a socket. */ | |
| @@ -724,8 +732,8 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, | |
| rc = lstat(unix_socket, &statbuf); | |
| #endif | |
| if(rc) { | |
| - | logmsg("Error binding socket, failed to stat %s (%d) %s", |
| - | unix_socket, errno, strerror(errno)); |
| + | logmsg("Error binding socket, failed to stat %s (%d) %s", unix_socket, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| return rc; | |
| } | |
| #ifdef S_IFSOCK | |
| @@ -737,8 +745,8 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket, | |
| /* dead socket, cleanup and retry bind */ | |
| rc = unlink(unix_socket); | |
| if(rc) { | |
| - | logmsg("Error binding socket, failed to unlink %s (%d) %s", |
| - | unix_socket, errno, strerror(errno)); |
| + | logmsg("Error binding socket, failed to unlink %s (%d) %s", unix_socket, |
| + | errno, curlx_strerror(errno, errbuf, sizeof(errbuf))); |
| return rc; | |
| } | |
| /* stale socket is gone, retry bind */ | |
| @@ -762,6 +770,7 @@ curl_socket_t sockdaemon(curl_socket_t sock, | |
| int delay = 20; | |
| int attempt = 0; | |
| int error = 0; | |
| + | char errbuf[STRERROR_LEN]; |
| #ifndef USE_UNIX_SOCKETS | |
| (void)unix_socket; | |
| @@ -775,14 +784,14 @@ curl_socket_t sockdaemon(curl_socket_t sock, | |
| if(rc) { | |
| error = SOCKERRNO; | |
| logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| if(maxretr) { | |
| rc = curlx_wait_ms(delay); | |
| if(rc) { | |
| /* should not happen */ | |
| error = SOCKERRNO; | |
| logmsg("curlx_wait_ms() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -799,7 +808,8 @@ curl_socket_t sockdaemon(curl_socket_t sock, | |
| if(rc) { | |
| logmsg("setsockopt(SO_REUSEADDR) failed %d times in %d ms. Error (%d) %s", | |
| - | attempt, totdelay, error, strerror(error)); |
| + | attempt, totdelay, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| logmsg("Continuing anyway..."); | |
| } | |
| @@ -836,12 +846,12 @@ curl_socket_t sockdaemon(curl_socket_t sock, | |
| error = SOCKERRNO; | |
| #ifdef USE_UNIX_SOCKETS | |
| if(socket_domain == AF_UNIX) | |
| - | logmsg("Error binding socket on path %s (%d) %s", |
| - | unix_socket, error, sstrerror(error)); |
| + | logmsg("Error binding socket on path %s (%d) %s", unix_socket, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| else | |
| #endif | |
| - | logmsg("Error binding socket on port %hu (%d) %s", |
| - | *listenport, error, sstrerror(error)); |
| + | logmsg("Error binding socket on port %hu (%d) %s", *listenport, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -865,7 +875,7 @@ curl_socket_t sockdaemon(curl_socket_t sock, | |
| if(getsockname(sock, &localaddr.sa, &la_size) < 0) { | |
| error = SOCKERRNO; | |
| logmsg("getsockname() failed with error (%d) %s", | |
| - | error, sstrerror(error)); |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| return CURL_SOCKET_BAD; | |
| } | |
| @@ -902,8 +912,8 @@ curl_socket_t sockdaemon(curl_socket_t sock, | |
| rc = listen(sock, 5); | |
| if(rc) { | |
| error = SOCKERRNO; | |
| - | logmsg("listen(%ld, 5) failed with error (%d) %s", |
| - | (long)sock, error, sstrerror(error)); |
| + | logmsg("listen(%ld, 5) failed with error (%d) %s", (long)sock, |
| + | error, curlx_strerror(error, errbuf, sizeof(errbuf))); |
| sclose(sock); | |
| return CURL_SOCKET_BAD; | |
| } | |