summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2011-04-05 21:56:05 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2011-04-05 21:56:05 +0000
commit2973057493524c8b729d4c85e077f111012a4aac (patch)
tree9ba493ad554e8b08e9a294a55e6d6e571583a3e2
parentcf696f26c9c0d7de351b9af8678375892d434255 (diff)
Notes
-rw-r--r--lib/libc/gen/errlst.c2
-rw-r--r--lib/libc/string/strerror.35
-rw-r--r--lib/libc/string/strerror.c2
-rw-r--r--tools/regression/lib/libc/string/test-strerror.c21
4 files changed, 19 insertions, 11 deletions
diff --git a/lib/libc/gen/errlst.c b/lib/libc/gen/errlst.c
index b105cc80cf40b..d8178236deed9 100644
--- a/lib/libc/gen/errlst.c
+++ b/lib/libc/gen/errlst.c
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
const char *const sys_errlist[] = {
- "Undefined error: 0", /* 0 - ENOERROR */
+ "No error: 0", /* 0 - ENOERROR */
"Operation not permitted", /* 1 - EPERM */
"No such file or directory", /* 2 - ENOENT */
"No such process", /* 3 - ESRCH */
diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3
index 2d6d206c10952..0ec6cb0af4062 100644
--- a/lib/libc/string/strerror.3
+++ b/lib/libc/string/strerror.3
@@ -32,7 +32,7 @@
.\" @(#)strerror.3 8.1 (Berkeley) 6/9/93
.\" $FreeBSD$
.\"
-.Dd October 12, 2004
+.Dd April 5, 2011
.Dt STRERROR 3
.Os
.Sh NAME
@@ -114,6 +114,9 @@ the range 0 <
.Fa errnum
<
.Fa sys_nerr .
+The number 0 is also recognized, although applications that take advantage of
+this are likely to use unspecified values of
+.Va errno .
.Pp
If insufficient storage is provided in
.Fa strerrbuf
diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c
index 890ed2139af82..57d253db46115 100644
--- a/lib/libc/string/strerror.c
+++ b/lib/libc/string/strerror.c
@@ -87,7 +87,7 @@ strerror_r(int errnum, char *strerrbuf, size_t buflen)
catd = catopen("libc", NL_CAT_LOCALE);
#endif
- if (errnum < 1 || errnum >= sys_nerr) {
+ if (errnum < 0 || errnum >= sys_nerr) {
errstr(errnum,
#if defined(NLS)
catgets(catd, 1, 0xffff, UPREFIX),
diff --git a/tools/regression/lib/libc/string/test-strerror.c b/tools/regression/lib/libc/string/test-strerror.c
index f5274ed7f2271..ffc1633bab2f1 100644
--- a/tools/regression/lib/libc/string/test-strerror.c
+++ b/tools/regression/lib/libc/string/test-strerror.c
@@ -42,17 +42,12 @@ main(void)
char *sret;
int iret;
- plan_tests(25);
+ plan_tests(27);
/*
* strerror() failure tests.
*/
errno = 0;
- sret = strerror(0);
- ok1(strcmp(sret, "Unknown error: 0") == 0);
- ok1(errno == EINVAL);
-
- errno = 0;
sret = strerror(INT_MAX);
snprintf(buf, sizeof(buf), "Unknown error: %d", INT_MAX);
ok1(strcmp(sret, buf) == 0);
@@ -62,6 +57,11 @@ main(void)
* strerror() success tests.
*/
errno = 0;
+ sret = strerror(0);
+ ok1(strcmp(sret, "No error: 0") == 0);
+ ok1(errno == 0);
+
+ errno = 0;
sret = strerror(EPERM);
ok1(strcmp(sret, "Operation not permitted") == 0);
ok1(errno == 0);
@@ -79,8 +79,8 @@ main(void)
* strerror_r() failure tests.
*/
memset(buf, '*', sizeof(buf));
- iret = strerror_r(0, buf, sizeof(buf));
- ok1(strcmp(buf, "Unknown error: 0") == 0);
+ iret = strerror_r(-1, buf, sizeof(buf));
+ ok1(strcmp(buf, "Unknown error: -1") == 0);
ok1(iret == EINVAL);
memset(buf, '*', sizeof(buf));
@@ -117,6 +117,11 @@ main(void)
* strerror_r() success tests.
*/
memset(buf, '*', sizeof(buf));
+ iret = strerror_r(0, buf, sizeof(buf));
+ ok1(strcmp(buf, "No error: 0") == 0);
+ ok1(iret == 0);
+
+ memset(buf, '*', sizeof(buf));
iret = strerror_r(EDEADLK, buf, sizeof(buf));
ok1(strcmp(buf, "Resource deadlock avoided") == 0);
ok1(iret == 0);