From 6421c8217b38d7b5605c652b89793b2de0192d91 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Nov 2026 15:45:17 +0100 Subject: Add libgamma_get_fd and fix some minor issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libgamma_strerror_r.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'libgamma_strerror_r.c') diff --git a/libgamma_strerror_r.c b/libgamma_strerror_r.c index c95d8a9..1076ed8 100644 --- a/libgamma_strerror_r.c +++ b/libgamma_strerror_r.c @@ -2,6 +2,22 @@ #include "common.h" +static const char * +libgamma_xsi_strerror_r(int (*function)(int, char *, size_t), int error_code, char *buf, size_t bufsize) +{ + int error = function(error_code, buf, bufsize); + errno = error; + return error ? NULL : buf; +} + + +static const char * +libgamma_gnu_strerror_r(char *(*function)(int, char *, size_t), int error_code, char *buf, size_t bufsize) +{ + return function(error_code, buf, bufsize); +} + + /** * Get a description of an error * @@ -36,11 +52,12 @@ libgamma_strerror_r(int error_code, char buf[], size_t bufsize) *buf = '\0'; if (error_code >= 0) { saved_errno = errno; - desc = _Generic(strerror_r(error_code, buf, bufsize), + desc = _Generic(&strerror_r, /* XSI strerror_r */ - int: (errno = (int)(intptr_t)strerror_r(error_code, buf, bufsize)) ? NULL : buf, + int (*)(int, char *, size_t): libgamma_xsi_strerror_r, /* GNU strerror_r */ - char *: (char *)(intptr_t)strerror_r(error_code, buf, bufsize)); + char *(*)(int, char *, size_t): libgamma_gnu_strerror_r) + (&strerror_r, error_code, buf, bufsize); if (desc == buf && (!bufsize || !*buf)) desc = NULL; if (desc) { -- cgit v1.3.1