diff options
Diffstat (limited to 'src/lib/libc/string/strerror_r.c')
-rw-r--r-- | src/lib/libc/string/strerror_r.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/libc/string/strerror_r.c b/src/lib/libc/string/strerror_r.c new file mode 100644 index 0000000000..aab6db5303 --- /dev/null +++ b/src/lib/libc/string/strerror_r.c | |||
@@ -0,0 +1,30 @@ | |||
1 | /* $OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $ */ | ||
2 | /* Public Domain <marc@snafu.org> */ | ||
3 | |||
4 | #if defined(LIBC_SCCS) && !defined(lint) | ||
5 | static char *rcsid = "$OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $"; | ||
6 | #endif /* LIBC_SCCS and not lint */ | ||
7 | |||
8 | #include <errno.h> | ||
9 | #include <limits.h> | ||
10 | #include <string.h> | ||
11 | |||
12 | extern char *__strerror(int, char *); | ||
13 | |||
14 | int | ||
15 | strerror_r(int errnum, char *strerrbuf, size_t buflen) | ||
16 | { | ||
17 | int save_errno; | ||
18 | int ret_errno; | ||
19 | char buf[NL_TEXTMAX]; | ||
20 | |||
21 | save_errno = errno; | ||
22 | errno = 0; | ||
23 | __strerror(errnum, buf); | ||
24 | if (strlcpy(strerrbuf, buf, buflen) >= buflen) | ||
25 | errno = ERANGE; | ||
26 | ret_errno = errno; | ||
27 | errno = save_errno; | ||
28 | |||
29 | return (ret_errno); | ||
30 | } | ||