From af5a49e489fdc04b9cf02547650d7aeaccd43793 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Mon, 14 Dec 2020 10:58:12 -0600 Subject: string: Add wrong strerror_r --- libgcompat/string.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libgcompat') diff --git a/libgcompat/string.c b/libgcompat/string.c index 9852bea..f2a2e87 100644 --- a/libgcompat/string.c +++ b/libgcompat/string.c @@ -1,9 +1,12 @@ #define _GNU_SOURCE /* mempcpy */ #include /* assert */ +#include /* dlsym, RTLD_NEXT */ #include /* NULL, size_t */ #include /* SIZE_MAX */ #include /* rand_r */ +#define strerror_r no_strerror_r #include /* memcpy, strcpy, strncat, strndup */ +#undef strerror_r #include /* time */ #include /* getpid */ @@ -210,6 +213,21 @@ char *__strdup(const char *string) return strdup(string); } +/** + * Non-POSIX strerror_r. + */ +static int (*real_strerror_r)(int, char *, size_t); + +char *strerror_r(int errnum, char *buf, size_t buflen) +{ + if (real_strerror_r == NULL) { + real_strerror_r = dlsym(RTLD_NEXT, "strerror_r"); + assert(real_strerror_r); + } + real_strerror_r(errnum, buf, buflen); + return buf; +} + /** * Concatenate a string with part of another, with buffer overflow checking. * -- cgit v1.2.3-70-g09d2