summaryrefslogtreecommitdiff
path: root/libgcompat
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-14 10:58:12 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-12-14 10:58:12 -0600
commitaf5a49e489fdc04b9cf02547650d7aeaccd43793 (patch)
tree1c05863179f523c0e8d6138eebfdd9a95d51a504 /libgcompat
parent11a020c38463b7617f9da2f180a7b30ffca86847 (diff)
downloadgcompat-af5a49e489fdc04b9cf02547650d7aeaccd43793.tar.gz
gcompat-af5a49e489fdc04b9cf02547650d7aeaccd43793.tar.bz2
gcompat-af5a49e489fdc04b9cf02547650d7aeaccd43793.tar.xz
gcompat-af5a49e489fdc04b9cf02547650d7aeaccd43793.zip
string: Add wrong strerror_r
Diffstat (limited to 'libgcompat')
-rw-r--r--libgcompat/string.c18
1 files changed, 18 insertions, 0 deletions
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.h> /* assert */
+#include <dlfcn.h> /* dlsym, RTLD_NEXT */
#include <stddef.h> /* NULL, size_t */
#include <stdint.h> /* SIZE_MAX */
#include <stdlib.h> /* rand_r */
+#define strerror_r no_strerror_r
#include <string.h> /* memcpy, strcpy, strncat, strndup */
+#undef strerror_r
#include <time.h> /* time */
#include <unistd.h> /* getpid */
@@ -211,6 +214,21 @@ char *__strdup(const char *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.
*
* LSB 5.0: LSB-Core-generic/baselib---strncat-chk-1.html