allowfunc snprintf
allowfunc socket
allowfunc sscanf
+allowfunc strerror
banfunc curl_maprintf
banfunc curl_mfprintf
banfunc curl_mprintf
curlx/inet_pton.c \
curlx/multibyte.c \
curlx/nonblock.c \
+ curlx/strerr.c \
curlx/strparse.c \
curlx/timediff.c \
curlx/timeval.c \
curlx/inet_pton.h \
curlx/multibyte.h \
curlx/nonblock.h \
+ curlx/strerr.h \
curlx/strparse.h \
curlx/timediff.h \
curlx/timeval.h \
#include "bufq.h"
#include "sendf.h"
#include "if2ip.h"
-#include "strerror.h"
#include "cfilters.h"
#include "cf-socket.h"
#include "connect.h"
#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 */
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;
#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
}
}
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;
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;
}
}
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;
#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;
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;
}
}
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;
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
}
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;
}
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;
}
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
#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
#include "version_win32.h"
/* provides curlx_verify_windows_version() */
+#include "strerr.h"
+/* The curlx_strerror() function */
+
#include "strparse.h"
/* The curlx_str_* parsing functions */
--- /dev/null
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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;
+}
--- /dev/null
+#ifndef HEADER_CURL_STRERR_H
+#define HEADER_CURL_STRERR_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 */
/*
* 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
#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.
*/
#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"
#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"
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) {
}
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",
* 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;
}
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;
}
}
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",
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",
#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"
#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"
#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)
{
*
***************************************************************************/
-#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
#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"
#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 */
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;
(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;
}
(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;
}
(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;
}
}
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;
}
}
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 */
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 */
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;
/* 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) {
#include "progress.h"
#include "cookie.h"
#include "strcase.h"
-#include "strerror.h"
#include "escape.h"
#include "share.h"
#include "content_encoding.h"
#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"
#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
#include "../cf-socket.h"
#include "../connect.h"
#include "../progress.h"
-#include "../strerror.h"
#include "../curlx/dynbuf.h"
#include "../http1.h"
#include "../select.h"
#include "../cf-socket.h"
#include "../connect.h"
#include "../progress.h"
-#include "../strerror.h"
#include "../curlx/dynbuf.h"
#include "../http1.h"
#include "../select.h"
#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"
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);
#include "../multiif.h"
#include "../connect.h"
#include "../progress.h"
-#include "../strerror.h"
#include "../select.h"
#include "../http1.h"
#include "vquic.h"
#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 */
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;
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;
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;
#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"
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);
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));
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));
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));
* 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");
#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"
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;
}
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) {
"vsnprintf" => 1,
"sscanf" => 1,
"strcat" => 1,
+ "strerror" => 1,
"strncat" => 1,
"strncpy" => 1,
"strtok_r" => 1,
../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 \
../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 \
#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
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
}
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;
*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;
}
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)
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
}
/* 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;
}
}
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. */
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);
/* 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) {
/* 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) {
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)));
+ }
}
}
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;
}
}
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 = \
/* ---------------------------------------------------------------- */
-#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) \
{
CURL *curl;
CURLcode res = CURLE_OK;
+ char errbuf[STRERROR_LEN];
FILE *hd_src;
int hd;
struct_stat file_info;
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 */
}
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;
{
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)
{
CURLcode res = CURLE_OK;
CURL *curl = NULL;
+ char errbuf[STRERROR_LEN];
FILE *hd_src = NULL;
int hd;
struct_stat file_info;
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;
}
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;
{
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)
{
CURL *curl;
CURLcode res = CURLE_OK;
+ char errbuf[STRERROR_LEN];
FILE *hd_src;
int hd;
struct_stat file_info;
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 */
}
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;
#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;
}
{
CURLcode res = CURLE_OK;
CURL *curl = NULL;
+ char errbuf[STRERROR_LEN];
FILE *hd_src = NULL;
int hd;
struct_stat file_info;
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;
}
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;
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;
}
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 \
/* 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;
}
int flag;
int rc;
int error;
+ char errbuf[STRERROR_LEN];
int result = 0;
pidname = ".dnsd.pid";
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;
}
(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;
}
#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;
}
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;
}
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);
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;
}
do {
ssize_t rc;
int error = 0;
+ char errbuf[STRERROR_LEN];
curl_socket_t sockfd = listenfd;
int maxfd = (int)sockfd;
if(rc < 0) {
logmsg("select() failed with error (%d) %s",
- error, strerror(error));
+ error, curlx_strerror(error, errbuf, sizeof(errbuf)));
return FALSE;
}
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. "
int wroteportfile = 0;
bool juggle_again;
int error;
+ char errbuf[STRERROR_LEN];
int arg = 1;
pidname = ".mqttd.pid";
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;
}
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 */
{
int res;
int error = 0;
+ char errbuf[STRERROR_LEN];
size_t written;
size_t writeleft;
FILE *dump;
/* !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;
}
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);
}
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;
}
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) {
bool sendfailure = FALSE;
size_t responsesize;
int error = 0;
+ char errbuf[STRERROR_LEN];
int res;
static char weare[256];
char responsedump[256];
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;
}
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;
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);
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);
/* 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;
}
}
struct rtspd_httprequest req;
int rc;
int error;
+ char errbuf[STRERROR_LEN];
int arg = 1;
memset(&req, 0, sizeof(req));
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;
}
(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;
}
#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;
}
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;
}
if(rc) {
error = SOCKERRNO;
logmsg("listen() failed with error (%d) %s",
- error, sstrerror(error));
+ error, curlx_strerror(error, errbuf, sizeof(errbuf)));
goto server_cleanup;
}
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;
}
}
if(rc < 0) {
+ char errbuf[STRERROR_LEN];
error = errno;
/* !checksrc! disable ERRNOVAR 1 */
if((error == EINTR) || (error == EAGAIN))
}
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;
}
}
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;
}
int maxfd = -99;
ssize_t rc;
int error = 0;
+ char errbuf[STRERROR_LEN];
unsigned char buffer[BUFFER_SIZE];
char data[16];
if(rc < 0) {
logmsg("select() failed with error (%d) %s",
- error, sstrerror(error));
+ error, curlx_strerror(error, errbuf, sizeof(errbuf)));
return FALSE;
}
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");
bool juggle_again;
int rc;
int error;
+ char errbuf[STRERROR_LEN];
int arg = 1;
enum sockmode mode = PASSIVE_LISTEN; /* default */
const char *addr = NULL;
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;
}
}
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;
}
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);
int i;
ssize_t rc;
int error = 0;
+ char errbuf[STRERROR_LEN];
curl_socket_t sockfd = listenfd;
int maxfd = (int)sockfd;
if(rc < 0) {
logmsg("select() failed with error (%d) %s",
- error, sstrerror(error));
+ error, curlx_strerror(error, errbuf, sizeof(errbuf)));
return FALSE;
}
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;
int wroteportfile = 0;
bool juggle_again;
int error;
+ char errbuf[STRERROR_LEN];
int arg = 1;
const char *unix_socket = NULL;
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;
}
#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
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 */
{
int res;
int error = 0;
+ char errbuf[STRERROR_LEN];
size_t written;
size_t writeleft;
FILE *dump;
/* !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;
}
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);
}
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)
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) {
bool sendfailure = FALSE;
size_t responsesize;
int error = 0;
+ char errbuf[STRERROR_LEN];
int res;
static char weare[256];
char responsedump[256];
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 {
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;
}
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);
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);
/* 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;
}
}
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 = "";
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;
}
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;
}
}
}
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;
}
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;
}
{
curl_socket_t msgsock = CURL_SOCKET_BAD;
int error;
+ char errbuf[STRERROR_LEN];
int flag = 1;
if(MAX_SOCKETS == num_sockets) {
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;
}
(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;
}
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];
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;
}
(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;
}
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;
}
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;
}
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;
}
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;
}
#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
struct errmsg {
int e_code;
- const char *e_msg;
+ char e_msg[STRERROR_LEN];
};
typedef union {
{ TFTP_EBADID, "Unknown transfer ID" },
{ TFTP_EEXISTS, "File already exists" },
{ TFTP_ENOUSER, "No such user" },
- { -1, 0 }
+ { -1, "" }
};
static const struct formats formata[] = {
int flag;
int rc;
int error;
+ char errbuf[STRERROR_LEN];
struct testcase test;
int result = 0;
srvr_sockaddr_union_t from;
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;
}
(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;
}
#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;
}
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;
}
/* 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;
}
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 */
}
else
partno = 0;
-
logmsg("requested test number %ld part %ld", testno, partno);
test->testno = testno;
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;
}
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);
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);
}
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 */
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);
{
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);
{
FILE *lockfile;
int error = 0;
+ char errbuf[STRERROR_LEN];
int res;
do {
/* !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)
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 */
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);
/* 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;
/* 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
struct sockaddr_un *sau)
{
int error;
+ char errbuf[STRERROR_LEN];
int rc;
size_t len = strlen(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 */
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. */
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
/* 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 */
int delay = 20;
int attempt = 0;
int error = 0;
+ char errbuf[STRERROR_LEN];
#ifndef USE_UNIX_SOCKETS
(void)unix_socket;
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;
}
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...");
}
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;
}
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;
}
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;
}