summaryrefslogtreecommitdiffstats
path: root/lib/libc/string/strerror_r.c
diff options
context:
space:
mode:
authormarc <marc@openbsd.org>2002-11-21 20:45:05 +0000
committermarc <marc@openbsd.org>2002-11-21 20:45:05 +0000
commitb418cc483f2c538a9dd6353a9d96390b80bb70cb (patch)
treed4cc57fe6ee5d13c58974e747235433942f3b53a /lib/libc/string/strerror_r.c
parentadd prototype for strerror_r (diff)
downloadwireguard-openbsd-b418cc483f2c538a9dd6353a9d96390b80bb70cb.tar.xz
wireguard-openbsd-b418cc483f2c538a9dd6353a9d96390b80bb70cb.zip
Add strerror_r and functions versions of getchar_unlocked and
putchar_unlocked. Crank the minor on related libs. OK fgs@, deraadt@
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);
+}