summaryrefslogtreecommitdiff
path: root/lib/libc/string/strerror_r.c
blob: aab6db5303cbd2e0f3c7338aec85ce949e7370c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}