From 2fffcd64b9de556bdc4e2d2bcc6a39eccf92957f Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 5 Feb 2024 13:01:08 +0100 Subject: [PATCH] [winpr] use winpr_strerror instead of strerror use the wrapper from WinPR to use the best implementation available. --- channels/audin/client/oss/audin_oss.c | 14 ++-- channels/printer/client/cups/printer_cups.c | 5 +- channels/rdpsnd/client/oss/rdpsnd_oss.c | 14 ++-- channels/tsmf/client/gstreamer/tsmf_X11.c | 3 +- channels/tsmf/client/oss/tsmf_oss.c | 58 +++++++------- .../src/main/cpp/android_freerdp.c | 4 +- client/X11/xf_client.c | 16 +++- client/X11/xf_window.c | 4 +- client/common/client.c | 10 ++- client/common/client_cliprdr_file.c | 4 +- libfreerdp/core/listener.c | 16 ++-- libfreerdp/core/tcp.c | 3 +- libfreerdp/core/transport.c | 3 +- libfreerdp/crypto/privatekey.c | 10 ++- libfreerdp/utils/http.c | 3 +- libfreerdp/utils/signal.c | 12 ++- winpr/libwinpr/comm/comm.c | 3 +- winpr/libwinpr/comm/comm_io.c | 25 ++++-- winpr/libwinpr/comm/comm_serial_sys.c | 56 +++++++++---- winpr/libwinpr/file/file.c | 79 ++++++++++++------- winpr/libwinpr/pipe/pipe.c | 12 ++- winpr/libwinpr/synch/mutex.c | 8 +- winpr/libwinpr/synch/semaphore.c | 6 +- winpr/libwinpr/synch/timer.c | 4 +- winpr/libwinpr/synch/wait.c | 13 ++- .../sysinfo/cpufeatures/cpu-features.c | 24 ++++-- winpr/libwinpr/thread/thread.c | 20 +++-- winpr/libwinpr/utils/print.c | 8 +- 28 files changed, 295 insertions(+), 142 deletions(-) diff --git a/channels/audin/client/oss/audin_oss.c b/channels/audin/client/oss/audin_oss.c index 21d8de9f5..b91188ba5 100644 --- a/channels/audin/client/oss/audin_oss.c +++ b/channels/audin/client/oss/audin_oss.c @@ -67,11 +67,15 @@ typedef struct rdpContext* rdpcontext; } AudinOSSDevice; -#define OSS_LOG_ERR(_text, _error) \ - do \ - { \ - if (_error != 0) \ - WLog_ERR(TAG, "%s: %i - %s\n", _text, _error, strerror(_error)); \ +#define OSS_LOG_ERR(_text, _error) \ + do \ + { \ + if (_error != 0) \ + { \ + char buffer[256] = { 0 }; \ + WLog_ERR(TAG, "%s: %i - %s\n", _text, _error, \ + winpr_strerror(_error, buffer, sizeof(buffer))); \ + } \ } while (0) static UINT32 audin_oss_get_format(const AUDIO_FORMAT* format) diff --git a/channels/printer/client/cups/printer_cups.c b/channels/printer/client/cups/printer_cups.c index 09e1bc76d..e112f52e8 100644 --- a/channels/printer/client/cups/printer_cups.c +++ b/channels/printer/client/cups/printer_cups.c @@ -56,8 +56,9 @@ static bool is_mac_os_sonoma_or_later(void) int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0); if (ret != 0) { - WLog_WARN(TAG, "sysctlbyname('kern.osrelease') failed with %s [%d]", strerror(errno), - errno); + char buffer[256] = { 0 }; + WLog_WARN(TAG, "sysctlbyname('kern.osrelease') failed with %s [%d]", + winpr_strerror(errno, buffer, sizeof(buffer)), errno); return false; } diff --git a/channels/rdpsnd/client/oss/rdpsnd_oss.c b/channels/rdpsnd/client/oss/rdpsnd_oss.c index 44a2fbbd5..0a72ffcd6 100644 --- a/channels/rdpsnd/client/oss/rdpsnd_oss.c +++ b/channels/rdpsnd/client/oss/rdpsnd_oss.c @@ -64,11 +64,15 @@ typedef struct AUDIO_FORMAT format; } rdpsndOssPlugin; -#define OSS_LOG_ERR(_text, _error) \ - do \ - { \ - if (_error != 0) \ - WLog_ERR(TAG, "%s: %i - %s", _text, _error, strerror(_error)); \ +#define OSS_LOG_ERR(_text, _error) \ + do \ + { \ + if (_error != 0) \ + { \ + char ebuffer[256] = { 0 }; \ + WLog_ERR(TAG, "%s: %i - %s", _text, _error, \ + winpr_strerror(_error, ebuffer, sizeof(ebuffer))); \ + } \ } while (0) static int rdpsnd_oss_get_format(const AUDIO_FORMAT* format) diff --git a/channels/tsmf/client/gstreamer/tsmf_X11.c b/channels/tsmf/client/gstreamer/tsmf_X11.c index e166a63fa..4e7b10996 100644 --- a/channels/tsmf/client/gstreamer/tsmf_X11.c +++ b/channels/tsmf/client/gstreamer/tsmf_X11.c @@ -188,8 +188,9 @@ int tsmf_platform_create(TSMFGstreamerDecoder* decoder) hdl->shmid = shm_open(get_shm_id(), (O_RDWR | O_CREAT), (PROT_READ | PROT_WRITE)); if (hdl->shmid == -1) { + char ebuffer[256] = { 0 }; WLog_ERR(TAG, "failed to get access to shared memory - shmget(%s): %i - %s", get_shm_id(), - errno, strerror(errno)); + errno, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return -2; } diff --git a/channels/tsmf/client/oss/tsmf_oss.c b/channels/tsmf/client/oss/tsmf_oss.c index d6e52a552..19a580b78 100644 --- a/channels/tsmf/client/oss/tsmf_oss.c +++ b/channels/tsmf/client/oss/tsmf_oss.c @@ -58,36 +58,40 @@ typedef struct UINT32 data_size_last; } TSMFOssAudioDevice; -#define OSS_LOG_ERR(_text, _error) \ - do \ - { \ - if (_error != 0) \ - WLog_ERR(TAG, "%s: %i - %s", _text, _error, strerror(_error)); \ - } while (0) +#define OSS_LOG_ERR(_text, _error) \ + do \ + { \ + if (_error != 0) \ + { \ + char ebuffer[256] = { 0 }; +WLog_ERR(TAG, "%s: %i - %s", _text, _error, winpr_strerror(_error, ebuffer, sizeof(ebuffer))); +} +} +while (0) -static BOOL tsmf_oss_open(ITSMFAudioDevice* audio, const char* device) -{ - int tmp; - TSMFOssAudioDevice* oss = (TSMFOssAudioDevice*)audio; - - if (oss == NULL || oss->pcm_handle != -1) - return FALSE; - - if (device == NULL) /* Default device. */ + static BOOL tsmf_oss_open(ITSMFAudioDevice* audio, const char* device) { - strncpy(oss->dev_name, "/dev/dsp", sizeof(oss->dev_name)); - } - else - { - strncpy(oss->dev_name, device, sizeof(oss->dev_name) - 1); - } + int tmp; + TSMFOssAudioDevice* oss = (TSMFOssAudioDevice*)audio; - if ((oss->pcm_handle = open(oss->dev_name, O_WRONLY)) < 0) - { - OSS_LOG_ERR("sound dev open failed", errno); - oss->pcm_handle = -1; - return FALSE; - } + if (oss == NULL || oss->pcm_handle != -1) + return FALSE; + + if (device == NULL) /* Default device. */ + { + strncpy(oss->dev_name, "/dev/dsp", sizeof(oss->dev_name)); + } + else + { + strncpy(oss->dev_name, device, sizeof(oss->dev_name) - 1); + } + + if ((oss->pcm_handle = open(oss->dev_name, O_WRONLY)) < 0) + { + OSS_LOG_ERR("sound dev open failed", errno); + oss->pcm_handle = -1; + return FALSE; + } #if 0 /* FreeBSD OSS implementation at this moment (2015.03) does not set PCM_CAP_OUTPUT flag. */ tmp = 0; diff --git a/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c b/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c index cd9871122..f5b26cc25 100644 --- a/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c +++ b/client/Android/Studio/freeRDPCore/src/main/cpp/android_freerdp.c @@ -650,7 +650,9 @@ JNIEXPORT jlong JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp if (setenv("HOME", _strdup(envStr), 1) != 0) { - WLog_FATAL(TAG, "Failed to set environemnt HOME=%s %s [%d]", env, strerror(errno), errno); + char ebuffer[256] = { 0 }; + WLog_FATAL(TAG, "Failed to set environemnt HOME=%s %s [%d]", env, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return (jlong)NULL; } diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index b759565e0..eda8899c2 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1228,7 +1228,9 @@ static BOOL xf_process_pipe(rdpContext* context, const char* pipe) int fd = open(pipe, O_NONBLOCK | O_RDONLY); if (fd < 0) { - WLog_ERR(TAG, "pipe '%s' open returned %s [%d]", pipe, strerror(errno), errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "pipe '%s' open returned %s [%d]", pipe, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } while (!freerdp_shall_disconnect_context(context)) @@ -1237,6 +1239,7 @@ static BOOL xf_process_pipe(rdpContext* context, const char* pipe) ssize_t rd = read(fd, buffer, sizeof(buffer) - 1); if (rd == 0) { + char ebuffer[256] = { 0 }; if ((errno == EAGAIN) || (errno == 0)) { Sleep(100); @@ -1244,12 +1247,15 @@ static BOOL xf_process_pipe(rdpContext* context, const char* pipe) } // EOF, abort reading. - WLog_ERR(TAG, "pipe '%s' read returned %s [%d]", pipe, strerror(errno), errno); + WLog_ERR(TAG, "pipe '%s' read returned %s [%d]", pipe, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); break; } else if (rd < 0) { - WLog_ERR(TAG, "pipe '%s' read returned %s [%d]", pipe, strerror(errno), errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "pipe '%s' read returned %s [%d]", pipe, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); break; } else @@ -1287,7 +1293,9 @@ static DWORD WINAPI xf_handle_pipe(void* arg) const int rc = mkfifo(pipe, S_IWUSR | S_IRUSR); if (rc != 0) { - WLog_ERR(TAG, "Failed to create named pipe '%s': %s [%d]", pipe, strerror(errno), errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "Failed to create named pipe '%s': %s [%d]", pipe, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return 0; } freerdp_add_signal_cleanup_handler(pipe, cleanup_pipe); diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 8cdf5351f..c71988806 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -526,7 +526,9 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int heig int rc = ftruncate(window->shmid, sizeof(window->handle)); if (rc != 0) { - DEBUG_X11("ftruncate failed with %s [%d]", strerror(rc), rc); + char ebuffer[256] = { 0 }; + DEBUG_X11("ftruncate failed with %s [%d]", winpr_strerror(rc, ebuffer, sizeof(ebuffer)), + rc); } else { diff --git a/client/common/client.c b/client/common/client.c index f37ffc52d..d1c2dfa4f 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -460,8 +460,9 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, rdp_auth_reason reaso if (freerdp_interruptible_get_line(instance->context, username, &username_size, stdin) < 0) { - WLog_ERR(TAG, "freerdp_interruptible_get_line returned %s [%d]", strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "freerdp_interruptible_get_line returned %s [%d]", + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); goto fail; } @@ -480,8 +481,9 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, rdp_auth_reason reaso if (freerdp_interruptible_get_line(instance->context, domain, &domain_size, stdin) < 0) { - WLog_ERR(TAG, "freerdp_interruptible_get_line returned %s [%d]", strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "freerdp_interruptible_get_line returned %s [%d]", + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); goto fail; } diff --git a/client/common/client_cliprdr_file.c b/client/common/client_cliprdr_file.c index 1fd9fccb6..9ca914be3 100644 --- a/client/common/client_cliprdr_file.c +++ b/client/common/client_cliprdr_file.c @@ -1362,10 +1362,12 @@ static CliprdrLocalFile* file_for_request(CliprdrFileContext* file, UINT32 lockI } if (!f->fp) { + char ebuffer[256] = { 0 }; writelog(file->log, WLOG_WARN, __FILE__, __func__, __LINE__, "[lockID %" PRIu32 ", index %" PRIu32 "] failed to open file '%s' [size %" PRId64 "] %s [%d]", - lockId, listIndex, f->name, f->size, strerror(errno), errno); + lockId, listIndex, f->name, f->size, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return NULL; } } diff --git a/libfreerdp/core/listener.c b/libfreerdp/core/listener.c index a7ff3fbfc..1e9976992 100644 --- a/libfreerdp/core/listener.c +++ b/libfreerdp/core/listener.c @@ -60,13 +60,16 @@ static BOOL freerdp_listener_open_from_vsock(freerdp_listener* instance, const c const int sockfd = socket(AF_VSOCK, SOCK_STREAM, 0); if (sockfd == -1) { - WLog_ERR(TAG, "Error creating socket: %s", strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "Error creating socket: %s", winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return FALSE; } const int flags = fcntl(sockfd, F_GETFL, 0); if (fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) == -1) { - WLog_ERR(TAG, "Error making socket nonblocking: %s", strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "Error making socket nonblocking: %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); closesocket((SOCKET)sockfd); return FALSE; } @@ -80,23 +83,26 @@ static BOOL freerdp_listener_open_from_vsock(freerdp_listener* instance, const c unsigned long val = strtoul(bind_address, &ptr, 10); if (errno || (val > UINT32_MAX)) { + char ebuffer[256] = { 0 }; WLog_ERR(TAG, "could not extract port from '%s', value=%ul, error=%s", bind_address, val, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return FALSE; } addr.svm_cid = val; if (bind(sockfd, (struct sockaddr*)&addr, sizeof(struct sockaddr_vm)) == -1) { + char ebuffer[256] = { 0 }; WLog_ERR(TAG, "Error binding vsock at cid %d port %d: %s", addr.svm_cid, port, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); closesocket((SOCKET)sockfd); return FALSE; } if (listen(sockfd, 10) == -1) { + char ebuffer[256] = { 0 }; WLog_ERR(TAG, "Error listening to socket at cid %d port %d: %s", addr.svm_cid, port, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); closesocket((SOCKET)sockfd); return FALSE; } diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index 906f60f47..3e7fc0d16 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -1124,8 +1124,9 @@ int freerdp_tcp_default_connect(rdpContext* context, rdpSettings* settings, cons unsigned long val = strtoul(hostname, &ptr, 10); if (errno || (val > UINT32_MAX)) { + char ebuffer[256] = { 0 }; WLog_ERR(TAG, "could not extract port from '%s', value=%ul, error=%s", hostname, val, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return -1; } addr.svm_cid = val; diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 39fbac40a..9d193bbb0 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -728,11 +728,12 @@ static void transport_bio_error_log(rdpTransport* transport, LPCSTR biofunc, BIO if (ERR_peek_error() == 0) { + char ebuffer[256] = { 0 }; const char* fmt = "%s returned a system error %d: %s"; if (saveerrno == 0) fmt = "%s retries exceeded"; WLog_PrintMessage(transport->log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc, - saveerrno, strerror(saveerrno)); + saveerrno, winpr_strerror(saveerrno, ebuffer, sizeof(ebuffer))); return; } diff --git a/libfreerdp/crypto/privatekey.c b/libfreerdp/crypto/privatekey.c index dee7d45c1..97c1dd074 100644 --- a/libfreerdp/crypto/privatekey.c +++ b/libfreerdp/crypto/privatekey.c @@ -156,7 +156,9 @@ static BOOL key_read_private(rdpPrivateKey* key) RSA* rsa = evp_pkey_to_rsa(key); if (!rsa) { - WLog_ERR(TAG, "unable to load RSA key: %s.", strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "unable to load RSA key: %s.", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); goto fail; } @@ -171,8 +173,12 @@ static BOOL key_read_private(rdpPrivateKey* key) break; default: - WLog_ERR(TAG, "unexpected error when checking RSA key: %s.", strerror(errno)); + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "unexpected error when checking RSA key: %s.", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); goto fail; + } } const BIGNUM* rsa_e = NULL; diff --git a/libfreerdp/utils/http.c b/libfreerdp/utils/http.c index 24de3fb96..70963f07f 100644 --- a/libfreerdp/utils/http.c +++ b/libfreerdp/utils/http.c @@ -238,8 +238,9 @@ BOOL freerdp_http_request(const char* url, const char* body, long* status_code, *response_length = strtoul(val, NULL, 10); if (errno) { + char ebuffer[256] = { 0 }; WLog_Print(log, WLOG_ERROR, "could not parse content length (%s): %s [%d]", val, - strerror(errno), errno); + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); goto out; } } diff --git a/libfreerdp/utils/signal.c b/libfreerdp/utils/signal.c index 506e98c76..487b9b0f8 100644 --- a/libfreerdp/utils/signal.c +++ b/libfreerdp/utils/signal.c @@ -73,14 +73,22 @@ static void lock(void) { const int rc = pthread_mutex_lock(&signal_handler_lock); if (rc != 0) - WLog_ERR(TAG, "[pthread_mutex_lock] failed with %s [%d]", strerror(rc), rc); + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "[pthread_mutex_lock] failed with %s [%d]", + winpr_strerror(rc, ebuffer, sizeof(ebuffer)), rc); + } } static void unlock(void) { const int rc = pthread_mutex_unlock(&signal_handler_lock); if (rc != 0) - WLog_ERR(TAG, "[pthread_mutex_lock] failed with %s [%d]", strerror(rc), rc); + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "[pthread_mutex_lock] failed with %s [%d]", + winpr_strerror(rc, ebuffer, sizeof(ebuffer)), rc); + } } static void term_handler(int signum) diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index fdfa2e938..d918ce82d 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -1298,8 +1298,9 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); CommLog_Print(WLOG_WARN, "could not read counters."); /* could not initialize counters but keep on. * diff --git a/winpr/libwinpr/comm/comm_io.c b/winpr/libwinpr/comm/comm_io.c index d4d99ecc0..1b0f278cf 100644 --- a/winpr/libwinpr/comm/comm_io.c +++ b/winpr/libwinpr/comm/comm_io.c @@ -241,7 +241,9 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, if (nbFds < 0) { - CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); goto return_false; } @@ -268,9 +270,10 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, } else { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "unexpected error on reading fd_read_event, errno=[%d] %s\n", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); /* FIXME: goto return_false ? */ } @@ -293,6 +296,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, if (nbRead < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "CommReadFile failed, ReadIntervalTimeout=%" PRIu32 ", ReadTotalTimeoutMultiplier=%" PRIu32 @@ -300,9 +304,9 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, pTimeouts->ReadIntervalTimeout, pTimeouts->ReadTotalTimeoutMultiplier, pTimeouts->ReadTotalTimeoutConstant, currentTermios.c_cc[VMIN], currentTermios.c_cc[VTIME]); - CommLog_Print(WLOG_WARN, - "CommReadFile failed, nNumberOfBytesToRead=%" PRIu32 ", errno=[%d] %s", - nNumberOfBytesToRead, errno, strerror(errno)); + CommLog_Print( + WLOG_WARN, "CommReadFile failed, nNumberOfBytesToRead=%" PRIu32 ", errno=[%d] %s", + nNumberOfBytesToRead, errno, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); if (errno == EAGAIN) { @@ -433,7 +437,9 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite if (nbFds < 0) { - CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); goto return_false; } @@ -460,9 +466,10 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite } else { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "unexpected error on reading fd_write_event, errno=[%d] %s\n", - errno, strerror(errno)); + errno, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); /* FIXME: goto return_false ? */ } @@ -488,10 +495,12 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite if (nbWritten < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "CommWriteFile failed after %" PRIu32 " bytes written, errno=[%d] %s\n", - *lpNumberOfBytesWritten, errno, strerror(errno)); + *lpNumberOfBytesWritten, errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); if (errno == EAGAIN) { diff --git a/winpr/libwinpr/comm/comm_serial_sys.c b/winpr/libwinpr/comm/comm_serial_sys.c index dd254cb28..62bc0b1e5 100644 --- a/winpr/libwinpr/comm/comm_serial_sys.c +++ b/winpr/libwinpr/comm/comm_serial_sys.c @@ -893,8 +893,9 @@ static BOOL _set_lines(WINPR_COMM* pComm, UINT32 lines) { if (ioctl(pComm->fd, TIOCMBIS, &lines) < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "TIOCMBIS ioctl failed, lines=0x%" PRIX32 ", errno=[%d] %s", lines, - errno, strerror(errno)); + errno, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -906,8 +907,9 @@ static BOOL _clear_lines(WINPR_COMM* pComm, UINT32 lines) { if (ioctl(pComm->fd, TIOCMBIC, &lines) < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "TIOCMBIC ioctl failed, lines=0x%" PRIX32 ", errno=[%d] %s", lines, - errno, strerror(errno)); + errno, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -986,7 +988,9 @@ static BOOL _get_modemstatus(WINPR_COMM* pComm, ULONG* pRegister) UINT32 lines = 0; if (ioctl(pComm->fd, TIOCMGET, &lines) < 0) { - CommLog_Print(WLOG_WARN, "TIOCMGET ioctl failed, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TIOCMGET ioctl failed, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1057,8 +1061,9 @@ static BOOL _set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask) if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); if (pComm->permissive) { @@ -1150,8 +1155,9 @@ static BOOL _purge(WINPR_COMM* pComm, const ULONG* pPurgeMask) { if (errno != EAGAIN) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "eventfd_write failed, errno=[%d] %s", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); } WINPR_ASSERT(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_WRITE */ @@ -1166,8 +1172,9 @@ static BOOL _purge(WINPR_COMM* pComm, const ULONG* pPurgeMask) { if (errno != EAGAIN) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "eventfd_write failed, errno=[%d] %s", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); } WINPR_ASSERT(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_READ */ @@ -1180,8 +1187,9 @@ static BOOL _purge(WINPR_COMM* pComm, const ULONG* pPurgeMask) if (tcflush(pComm->fd, TCOFLUSH) < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "tcflush(TCOFLUSH) failure, errno=[%d] %s", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_CANCELLED); return FALSE; } @@ -1193,8 +1201,9 @@ static BOOL _purge(WINPR_COMM* pComm, const ULONG* pPurgeMask) if (tcflush(pComm->fd, TCIFLUSH) < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "tcflush(TCIFLUSH) failure, errno=[%d] %s", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_CANCELLED); return FALSE; } @@ -1221,8 +1230,9 @@ static BOOL _get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus) ZeroMemory(¤tCounters, sizeof(struct serial_icounter_struct)); if (ioctl(pComm->fd, TIOCGICOUNT, ¤tCounters) < 0) { + char ebuffer[256] = { 0 }; CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); CommLog_Print(WLOG_WARN, " could not read counters."); if (pComm->permissive) @@ -1292,7 +1302,9 @@ static BOOL _get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus) if (ioctl(pComm->fd, TIOCINQ, &(pCommstatus->AmountInInQueue)) < 0) { - CommLog_Print(WLOG_WARN, "TIOCINQ ioctl failed, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TIOCINQ ioctl failed, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); LeaveCriticalSection(&pComm->EventsLock); @@ -1303,7 +1315,9 @@ static BOOL _get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus) if (ioctl(pComm->fd, TIOCOUTQ, &(pCommstatus->AmountInOutQueue)) < 0) { - CommLog_Print(WLOG_WARN, "TIOCOUTQ ioctl failed, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TIOCOUTQ ioctl failed, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); LeaveCriticalSection(&pComm->EventsLock); @@ -1476,7 +1490,9 @@ static BOOL _set_break_on(WINPR_COMM* pComm) { if (ioctl(pComm->fd, TIOCSBRK, NULL) < 0) { - CommLog_Print(WLOG_WARN, "TIOCSBRK ioctl failed, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TIOCSBRK ioctl failed, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1488,7 +1504,9 @@ static BOOL _set_break_off(WINPR_COMM* pComm) { if (ioctl(pComm->fd, TIOCCBRK, NULL) < 0) { - CommLog_Print(WLOG_WARN, "TIOCSBRK ioctl failed, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TIOCSBRK ioctl failed, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1500,7 +1518,9 @@ static BOOL _set_xoff(WINPR_COMM* pComm) { if (tcflow(pComm->fd, TCIOFF) < 0) { - CommLog_Print(WLOG_WARN, "TCIOFF failure, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TCIOFF failure, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1512,7 +1532,9 @@ static BOOL _set_xon(WINPR_COMM* pComm) { if (tcflow(pComm->fd, TCION) < 0) { - CommLog_Print(WLOG_WARN, "TCION failure, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TCION failure, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1525,7 +1547,9 @@ static BOOL _get_dtrrts(WINPR_COMM* pComm, ULONG* pMask) UINT32 lines = 0; if (ioctl(pComm->fd, TIOCMGET, &lines) < 0) { - CommLog_Print(WLOG_WARN, "TIOCMGET ioctl failed, errno=[%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + CommLog_Print(WLOG_WARN, "TIOCMGET ioctl failed, errno=[%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_IO_DEVICE); return FALSE; } diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index a350fcbae..9dfa885db 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -20,6 +20,7 @@ */ #include +#include #if defined(__FreeBSD_kernel__) && defined(__GLIBC__) #define _GNU_SOURCE @@ -108,8 +109,9 @@ static BOOL FileSetEndOfFile(HANDLE hFile) if (ftruncate(fileno(pFile->fp), size) < 0) { - WLog_ERR(TAG, "ftruncate %s failed with %s [0x%08X]", pFile->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "ftruncate %s failed with %s [0x%08X]", pFile->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); SetLastError(map_posix_err(errno)); return FALSE; } @@ -153,8 +155,9 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDist if (_fseeki64(pFile->fp, offset, whence)) { - WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", pFile->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", pFile->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return INVALID_SET_FILE_POINTER; } @@ -187,8 +190,9 @@ static BOOL FileSetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, if (_fseeki64(pFile->fp, liDistanceToMove.QuadPart, whence)) { - WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", pFile->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", pFile->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } @@ -283,15 +287,17 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) if (cur < 0) { - WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return INVALID_FILE_SIZE; } if (_fseeki64(file->fp, 0, SEEK_END) != 0) { - WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", file->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", file->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return INVALID_FILE_SIZE; } @@ -299,15 +305,17 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh) if (size < 0) { - WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return INVALID_FILE_SIZE; } if (_fseeki64(file->fp, cur, SEEK_SET) != 0) { - WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return INVALID_FILE_SIZE; } @@ -332,7 +340,9 @@ static BOOL FileGetFileInformationByHandle(HANDLE hFile, if (fstat(fileno(pFile->fp), &st) == -1) { - WLog_ERR(TAG, "fstat failed with %s [%#08X]", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "fstat failed with %s [%#08X]", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return FALSE; } @@ -425,7 +435,9 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, if (fcntl(fileno(pFile->fp), lckcmd, &lock) == -1) { - WLog_ERR(TAG, "F_SETLK failed with %s [0x%08X]", strerror(errno), errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "F_SETLK failed with %s [0x%08X]", + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } #else @@ -439,7 +451,9 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, if (flock(fileno(pFile->fp), lock) < 0) { - WLog_ERR(TAG, "flock failed with %s [0x%08X]", strerror(errno), errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "flock failed with %s [0x%08X]", + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } #endif @@ -473,16 +487,18 @@ static BOOL FileUnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffs lock.l_type = F_UNLCK; if (fcntl(fileno(pFile->fp), F_GETLK, &lock) == -1) { - WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]", pFile->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]", pFile->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } #else if (flock(fileno(pFile->fp), LOCK_UN) < 0) { + char ebuffer[256] = { 0 }; WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [0x%08X]", pFile->lpFileName, - strerror(errno), errno); + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } #endif @@ -521,15 +537,17 @@ static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfByte lock.l_type = F_UNLCK; if (fcntl(fileno(pFile->fp), F_GETLK, &lock) == -1) { - WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]", pFile->lpFileName, strerror(errno), - errno); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]", pFile->lpFileName, + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } #else if (flock(fileno(pFile->fp), LOCK_UN) < 0) { + char ebuffer[256] = { 0 }; WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [0x%08X]", pFile->lpFileName, - strerror(errno), errno); + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); return FALSE; } #endif @@ -766,9 +784,13 @@ UINT32 map_posix_err(int fs_errno) break; default: - WLog_ERR(TAG, "Missing ERRNO mapping %s [%d]", strerror(fs_errno), fs_errno); + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "Missing ERRNO mapping %s [%d]", + winpr_strerror(fs_errno, ebuffer, sizeof(ebuffer)), fs_errno); rc = STATUS_UNSUCCESSFUL; - break; + } + break; } return (UINT32)rc; @@ -908,10 +930,13 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw if (flock(fileno(pFile->fp), lock) < 0) #endif { + char ebuffer[256] = { 0 }; #ifdef __sun - WLog_ERR(TAG, "F_SETLKW failed with %s [0x%08X]", strerror(errno), errno); + WLog_ERR(TAG, "F_SETLKW failed with %s [0x%08X]", + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); #else - WLog_ERR(TAG, "flock failed with %s [0x%08X]", strerror(errno), errno); + WLog_ERR(TAG, "flock failed with %s [0x%08X]", + winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno); #endif SetLastError(map_posix_err(errno)); diff --git a/winpr/libwinpr/pipe/pipe.c b/winpr/libwinpr/pipe/pipe.c index 34548e909..7ce673c08 100644 --- a/winpr/libwinpr/pipe/pipe.c +++ b/winpr/libwinpr/pipe/pipe.c @@ -649,7 +649,9 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD if ((serverfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - WLog_ERR(TAG, "CreateNamedPipeA: socket error, %s", strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "CreateNamedPipeA: socket error, %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); goto out; } @@ -658,13 +660,17 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD if (bind(serverfd, (struct sockaddr*)&s, sizeof(struct sockaddr_un)) == -1) { - WLog_ERR(TAG, "CreateNamedPipeA: bind error, %s", strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "CreateNamedPipeA: bind error, %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); goto out; } if (listen(serverfd, 2) == -1) { - WLog_ERR(TAG, "CreateNamedPipeA: listen error, %s", strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "CreateNamedPipeA: listen error, %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); goto out; } diff --git a/winpr/libwinpr/synch/mutex.c b/winpr/libwinpr/synch/mutex.c index b86f2d43a..c2fc7af0a 100644 --- a/winpr/libwinpr/synch/mutex.c +++ b/winpr/libwinpr/synch/mutex.c @@ -64,7 +64,9 @@ BOOL MutexCloseHandle(HANDLE handle) if ((rc = pthread_mutex_destroy(&mutex->mutex))) { - WLog_ERR(TAG, "pthread_mutex_destroy failed with %s [%d]", strerror(rc), rc); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "pthread_mutex_destroy failed with %s [%d]", + winpr_strerror(rc, ebuffer, sizeof(ebuffer)), rc); #if defined(WITH_DEBUG_MUTEX) { size_t used = 0, i; @@ -230,7 +232,9 @@ BOOL ReleaseMutex(HANDLE hMutex) if (rc) { - WLog_ERR(TAG, "pthread_mutex_unlock failed with %s [%d]", strerror(rc), rc); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "pthread_mutex_unlock failed with %s [%d]", + winpr_strerror(rc, ebuffer, sizeof(ebuffer)), rc); return FALSE; } diff --git a/winpr/libwinpr/synch/semaphore.c b/winpr/libwinpr/synch/semaphore.c index 9288db707..0be372430 100644 --- a/winpr/libwinpr/synch/semaphore.c +++ b/winpr/libwinpr/synch/semaphore.c @@ -18,7 +18,7 @@ */ #include - +#include #include #include "synch.h" @@ -63,7 +63,9 @@ static DWORD SemaphoreCleanupHandle(HANDLE handle) if (length != 1) { - WLog_ERR(TAG, "semaphore read() failure [%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "semaphore read() failure [%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return WAIT_FAILED; } diff --git a/winpr/libwinpr/synch/timer.c b/winpr/libwinpr/synch/timer.c index 5b47fec28..dd1876b05 100644 --- a/winpr/libwinpr/synch/timer.c +++ b/winpr/libwinpr/synch/timer.c @@ -84,6 +84,7 @@ static DWORD TimerCleanupHandle(HANDLE handle) { if (length < 0) { + char ebuffer[256] = { 0 }; switch (errno) { case ETIMEDOUT: @@ -94,7 +95,8 @@ static DWORD TimerCleanupHandle(HANDLE handle) break; } - WLog_ERR(TAG, "timer read() failure [%d] %s", errno, strerror(errno)); + WLog_ERR(TAG, "timer read() failure [%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); } else { diff --git a/winpr/libwinpr/synch/wait.c b/winpr/libwinpr/synch/wait.c index 2a6d9c41c..b04aaef90 100644 --- a/winpr/libwinpr/synch/wait.c +++ b/winpr/libwinpr/synch/wait.c @@ -209,7 +209,9 @@ DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertabl } else if (ret < 0) { - WLog_ERR(TAG, "waitpid failure [%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "waitpid failure [%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); SetLastError(ERROR_INTERNAL_ERROR); return WAIT_FAILED; } @@ -310,7 +312,9 @@ DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertabl status = pollset_poll(&pollset, dwMilliseconds); if (status < 0) { - WLog_ERR(TAG, "pollset_poll() failure [%d] %s", errno, strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "pollset_poll() failure [%d] %s", errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); goto out; } } @@ -464,12 +468,13 @@ DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWait status = pollset_poll(&pollset, waitTime); if (status < 0) { + char ebuffer[256] = { 0 }; #ifdef WINPR_HAVE_POLL_H WLog_ERR(TAG, "poll() handle %" PRIu32 " (%" PRIu32 ") failure [%d] %s", index, - nCount, errno, strerror(errno)); + nCount, errno, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); #else WLog_ERR(TAG, "select() handle %" PRIu32 " (%" PRIu32 ") failure [%d] %s", index, - nCount, errno, strerror(errno)); + nCount, errno, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); #endif winpr_log_backtrace(TAG, WLOG_ERROR, 20); SetLastError(ERROR_INTERNAL_ERROR); diff --git a/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c b/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c index d8d59d0c2..b13832d25 100644 --- a/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c +++ b/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c @@ -144,7 +144,8 @@ static int get_file_size(const char* pathname) if (fd < 0) { - D("Can't open %s: %s\n", pathname, strerror(errno)); + char ebuffer[256] = { 0 }; + D("Can't open %s: %s\n", pathname, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return -1; } @@ -154,10 +155,12 @@ static int get_file_size(const char* pathname) if (ret < 0) { + char ebuffer[256] = { 0 }; if (errno == EINTR) continue; - D("Error while reading %s: %s\n", pathname, strerror(errno)); + D("Error while reading %s: %s\n", pathname, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); break; } @@ -183,7 +186,8 @@ static int read_file(const char* pathname, char* buffer, size_t buffsize) if (fd < 0) { - D("Could not open %s: %s\n", pathname, strerror(errno)); + char ebuffer[256] = { 0 }; + D("Could not open %s: %s\n", pathname, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return -1; } @@ -195,10 +199,12 @@ static int read_file(const char* pathname, char* buffer, size_t buffsize) if (ret < 0) { + char ebuffer[256] = { 0 }; if (errno == EINTR) continue; - D("Error while reading from %s: %s\n", pathname, strerror(errno)); + D("Error while reading from %s: %s\n", pathname, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); if (count == 0) count = -1; @@ -476,7 +482,8 @@ static void cpulist_read_from(CpuList* list, const char* filename) if (filelen < 0) { - D("Could not read %s: %s\n", filename, strerror(errno)); + char ebuffer[256] = { 0 }; + D("Could not read %s: %s\n", filename, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return; } @@ -586,7 +593,8 @@ static uint32_t get_elf_hwcap_from_proc_self_auxv(void) if (fd < 0) { - D("Could not open %s: %s\n", filepath, strerror(errno)); + char ebuffer[256] = { 0 }; + D("Could not open %s: %s\n", filepath, winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return 0; } @@ -604,7 +612,9 @@ static uint32_t get_elf_hwcap_from_proc_self_auxv(void) if (ret < 0) { - D("Error while reading %s: %s\n", filepath, strerror(errno)); + char ebuffer[256] = { 0 }; + D("Error while reading %s: %s\n", filepath, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); break; } diff --git a/winpr/libwinpr/thread/thread.c b/winpr/libwinpr/thread/thread.c index b239162ba..fcc83e4da 100644 --- a/winpr/libwinpr/thread/thread.c +++ b/winpr/libwinpr/thread/thread.c @@ -132,7 +132,8 @@ static BOOL run_mutex_init_(int (*fkt)(pthread_mutex_t*, const pthread_mutexattr rc = fkt(mutex, mutexattr); if (rc != 0) { - WLog_WARN(TAG, "[%s] failed with [%s]", name, strerror(rc)); + char ebuffer[256] = { 0 }; + WLog_WARN(TAG, "[%s] failed with [%s]", name, winpr_strerror(rc, ebuffer, sizeof(ebuffer))); } return rc == 0; } @@ -149,7 +150,8 @@ static BOOL run_mutex_fkt_(int (*fkt)(pthread_mutex_t* mux), const char* name, rc = fkt(mutex); if (rc != 0) { - WLog_WARN(TAG, "[%s] failed with [%s]", name, strerror(rc)); + char ebuffer[256] = { 0 }; + WLog_WARN(TAG, "[%s] failed with [%s]", name, winpr_strerror(rc, ebuffer, sizeof(ebuffer))); } return rc == 0; } @@ -166,7 +168,8 @@ static BOOL run_cond_init_(int (*fkt)(pthread_cond_t*, const pthread_condattr_t* rc = fkt(condition, conditionattr); if (rc != 0) { - WLog_WARN(TAG, "[%s] failed with [%s]", name, strerror(rc)); + char ebuffer[256] = { 0 }; + WLog_WARN(TAG, "[%s] failed with [%s]", name, winpr_strerror(rc, ebuffer, sizeof(ebuffer))); } return rc == 0; } @@ -183,7 +186,8 @@ static BOOL run_cond_fkt_(int (*fkt)(pthread_cond_t* mux), const char* name, rc = fkt(condition); if (rc != 0) { - WLog_WARN(TAG, "[%s] failed with [%s]", name, strerror(rc)); + char ebuffer[256] = { 0 }; + WLog_WARN(TAG, "[%s] failed with [%s]", name, winpr_strerror(rc, ebuffer, sizeof(ebuffer))); } return rc == 0; } @@ -259,7 +263,9 @@ static BOOL mux_condition_bundle_wait(mux_condition_bundle* bundle, const char* int r = pthread_cond_wait(&bundle->cond, &bundle->mux); if (r != 0) { - WLog_ERR(TAG, "failed to wait for %s [%s]", name, strerror(r)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "failed to wait for %s [%s]", name, + winpr_strerror(r, ebuffer, sizeof(ebuffer))); switch (r) { case ENOTRECOVERABLE: @@ -311,7 +317,9 @@ static DWORD ThreadCleanupHandle(HANDLE handle) if (rc != 0) { - WLog_ERR(TAG, "pthread_join failure: [%d] %s", rc, strerror(rc)); + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "pthread_join failure: [%d] %s", rc, + winpr_strerror(rc, ebuffer, sizeof(ebuffer))); goto fail; } else diff --git a/winpr/libwinpr/utils/print.c b/winpr/libwinpr/utils/print.c index 486305106..de272a909 100644 --- a/winpr/libwinpr/utils/print.c +++ b/winpr/libwinpr/utils/print.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -67,8 +68,9 @@ void winpr_HexLogDump(wLog* log, UINT32 lvl, const void* data, size_t length) if (!buffer) { + char ebuffer[256] = { 0 }; WLog_Print(log, WLOG_ERROR, "malloc(%" PRIuz ") failed with [%" PRIuz "] %s", blen, errno, - strerror(errno)); + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return; } @@ -137,7 +139,9 @@ void winpr_CArrayDump(const char* tag, UINT32 level, const void* data, size_t le if (!buffer) { - WLog_ERR(tag, "malloc(%" PRIuz ") failed with [%d] %s", llen, errno, strerror(errno)); + char ebuffer[256] = { 0 }; + WLog_ERR(tag, "malloc(%" PRIuz ") failed with [%d] %s", llen, errno, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); return; }