Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/string/strerror.c
Show All 40 Lines | |||||
#include <limits.h> | #include <limits.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include "errlst.h" | #include "errlst.h" | ||||
#define UPREFIX "Unknown error" | |||||
/* | /* | ||||
* Define a buffer size big enough to describe a 64-bit signed integer | * Define buffer big enough to contain delimiter (": ", 2 bytes), | ||||
* converted to ASCII decimal (19 bytes), with an optional leading sign | * 64-bit signed integer converted to ASCII decimal (19 bytes) with | ||||
* (1 byte); finally, we get the prefix, delimiter (": ") and a trailing | * optional leading sign (1 byte), and a trailing NUL. | ||||
* NUL from UPREFIX. | |||||
*/ | */ | ||||
#define EBUFSIZE (20 + 2 + sizeof(UPREFIX)) | #define EBUFSIZE (2 + 19 + 1 + 1) | ||||
/* | /* | ||||
* Doing this by hand instead of linking with stdio(3) avoids bloat for | * Doing this by hand instead of linking with stdio(3) avoids bloat for | ||||
* statically linked binaries. | * statically linked binaries. | ||||
*/ | */ | ||||
static void | static void | ||||
errstr(int num, char *uprefix, char *buf, size_t len) | errstr(int num, char *uprefix, char *buf, size_t len) | ||||
{ | { | ||||
Show All 23 Lines | #if defined(NLS) | ||||
int saved_errno = errno; | int saved_errno = errno; | ||||
nl_catd catd; | nl_catd catd; | ||||
catd = catopen("libc", NL_CAT_LOCALE); | catd = catopen("libc", NL_CAT_LOCALE); | ||||
#endif | #endif | ||||
if (errnum < 0 || errnum >= __hidden_sys_nerr) { | if (errnum < 0 || errnum >= __hidden_sys_nerr) { | ||||
errstr(errnum, | errstr(errnum, | ||||
#if defined(NLS) | #if defined(NLS) | ||||
catgets(catd, 1, 0xffff, UPREFIX), | catgets(catd, 1, 0xffff, __uprefix), | ||||
#else | #else | ||||
UPREFIX, | __uprefix, | ||||
#endif | #endif | ||||
strerrbuf, buflen); | strerrbuf, buflen); | ||||
retval = EINVAL; | retval = EINVAL; | ||||
} else { | } else { | ||||
if (strlcpy(strerrbuf, | if (strlcpy(strerrbuf, | ||||
#if defined(NLS) | #if defined(NLS) | ||||
catgets(catd, 1, errnum, __hidden_sys_errlist[errnum]), | catgets(catd, 1, errnum, __hidden_sys_errlist[errnum]), | ||||
#else | #else | ||||
Show All 23 Lines |