diff options
author | Wes Peters <wes@FreeBSD.org> | 2001-12-07 06:28:58 +0000 |
---|---|---|
committer | Wes Peters <wes@FreeBSD.org> | 2001-12-07 06:28:58 +0000 |
commit | 556f162ac01ccf2a3f501c0090aa6011fd723fdd (patch) | |
tree | 13ab748ad6a3bd42035b82a51f7ead77dbbf376b /lib/libc/string/strerror.c | |
parent | a28920935a477041c8ff4320fd31f9d09b9e3606 (diff) |
Notes
Diffstat (limited to 'lib/libc/string/strerror.c')
-rw-r--r-- | lib/libc/string/strerror.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index e0f4cd3f778c..55840f1bae4c 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -46,9 +46,9 @@ strerror_r(int errnum, char *strerrbuf, size_t buflen) { int len; - if ((errnum > 0) && (errnum < sys_nerr)) { + if ((errnum >= 0) && (errnum < sys_nerr)) { len = strlcpy(strerrbuf, (char *)sys_errlist[errnum], buflen); - return ((len <= buflen) ? 0 : ERANGE); + return ((len < buflen) ? 0 : ERANGE); } return (EINVAL); } @@ -71,10 +71,15 @@ strerror(num) char tmp[NUMLEN]; /* temporary number */ static char ebuf[EBUFLEN]; /* error message */ - if ((num > 0) && (num < sys_nerr)) + if ((num >= 0) && (num < sys_nerr)) return ((char *)sys_errlist[num]); /* + * Set errno to EINVAL per P1003.1-200x Draft June 14, 2001. + */ + errno = EINVAL; + + /* * Print unknown errno by hand so we don't link to stdio(3). * This collects the ASCII digits in reverse order. */ @@ -106,8 +111,20 @@ main() char mybuf[64]; int ret; + errno = 0; + + printf("strerror(0) yeilds: %s\n", strerror(0)); + printf("strerror(1) yeilds: %s\n", strerror(1)); printf("strerror(47) yeilds: %s\n", strerror(47)); + printf("strerror(sys_nerr - 1) yeilds: %s\n", strerror(sys_nerr - 1)); + printf("errno = %d\n", errno); errno = 0; + + printf("strerror(sys_nerr) yeilds: %s\n", strerror(sys_nerr)); + printf("errno = %d\n", errno); errno = 0; + printf("strerror(437) yeilds: %s\n", strerror(437)); + printf("errno = %d\n", errno); errno = 0; + printf("strerror(LONG_MAX) yeilds: %s\n", strerror(LONG_MAX)); printf("strerror(LONG_MIN) yeilds: %s\n", strerror(LONG_MIN)); printf("strerror(ULONG_MAX) yeilds: %s\n", strerror(ULONG_MAX)); |