diff options
Diffstat (limited to 'libgamma_strerror_r.c')
| -rw-r--r-- | libgamma_strerror_r.c | 23 |
1 files changed, 20 insertions, 3 deletions
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) { |
