[uwac] add strerror_r detection and use

This commit is contained in:
akallabeth 2024-09-28 13:41:46 +02:00
parent a820912a24
commit ba47e1936f
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
5 changed files with 25 additions and 2 deletions

View File

@ -49,6 +49,9 @@ option(UWAC_HAVE_PIXMAN_REGION "Use PIXMAN or FreeRDP for region calculations" "
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/)
include(CommonConfigOptions)
include(CheckFunctionExists)
check_function_exists(strerror_r UWAC_HAVE_STRERROR_R)
# Check for cmake compatibility (enable/disable features)
include(FindFeature)

View File

@ -402,8 +402,9 @@ UwacDisplay* UwacOpenDisplay(const char* name, UwacReturnCode* err)
if (ret->display == NULL)
{
char buffer[256] = { 0 };
(void)fprintf(stderr, "failed to connect to Wayland display %s: %s\n", name,
strerror(errno));
uwac_strerror(errno, buffer, sizeof(buffer)));
*err = UWAC_ERROR_UNABLE_TO_CONNECT;
goto out_free;
}

View File

@ -75,8 +75,11 @@ static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src,
wl_shm_pool_destroy(pool);
if (munmap(data, size) < 0)
{
char buffer[256] = { 0 };
(void)fprintf(stderr, "%s: munmap(%p, %zu) failed with [%d] %s\n", __func__, data, size,
errno, strerror(errno));
errno, uwac_strerror(errno, buffer, sizeof(buffer)));
}
error_mmap:
close(fd);

View File

@ -24,6 +24,9 @@
#define UWAC_UTILS_H_
#include <stdlib.h>
#include <string.h>
#include <uwac/config.h>
#define min(a, b) (a) < (b) ? (a) : (b)
@ -44,4 +47,16 @@ char* xstrdup(const char* s);
void* xrealloc(void* p, size_t s);
static inline char* uwac_strerror(int dw, char* dmsg, size_t size)
{
#ifdef __STDC_LIB_EXT1__
(void)strerror_s(dw, dmsg, size);
#elif defined(UWAC_HAVE_STRERROR_R)
(void)strerror_r(dw, dmsg, size);
#else
(void)_snprintf(dmsg, size, "%s", strerror(dw));
#endif
return dmsg;
}
#endif /* UWAC_UTILS_H_ */

View File

@ -7,5 +7,6 @@
#cmakedefine UWAC_HAVE_SYSLOG_H
#cmakedefine UWAC_HAVE_JOURNALD_H
#cmakedefine UWAC_HAVE_PIXMAN_REGION
#cmakedefine UWAC_HAVE_STRERROR_R
#endif /* UWAC_CONFIG_H */