summaryrefslogtreecommitdiffstats
path: root/lib/libc/string/strerror_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/string/strerror_r.c')
-rw-r--r--lib/libc/string/strerror_r.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/libc/string/strerror_r.c b/lib/libc/string/strerror_r.c
new file mode 100644
index 00000000000..aab6db5303c
--- /dev/null
+++ b/lib/libc/string/strerror_r.c
@@ -0,0 +1,30 @@
+/* $OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $ */
+/* Public Domain <marc@snafu.org> */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
+
+extern char *__strerror(int, char *);
+
+int
+strerror_r(int errnum, char *strerrbuf, size_t buflen)
+{
+ int save_errno;
+ int ret_errno;
+ char buf[NL_TEXTMAX];
+
+ save_errno = errno;
+ errno = 0;
+ __strerror(errnum, buf);
+ if (strlcpy(strerrbuf, buf, buflen) >= buflen)
+ errno = ERANGE;
+ ret_errno = errno;
+ errno = save_errno;
+
+ return (ret_errno);
+}