From c902a38c4a1577f5b9a27832540f1a955ea78038 Mon Sep 17 00:00:00 2001 From: jilles Date: Tue, 5 Apr 2011 21:56:05 +0000 Subject: Allow strerror(0) and strerror_r(0, ...). Of course, strerror_r() may still fail with ERANGE. Although the POSIX specification said this could fail with EINVAL and doing this likely indicates invalid use of errno, most other implementations permitted it, various POSIX testsuites require it to work (matching the older sys_errlist array) and apparently some applications depend on it. PR: standards/151316 MFC after: 1 week --- tools/regression/lib/libc/string/test-strerror.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tools/regression/lib/libc/string/test-strerror.c') diff --git a/tools/regression/lib/libc/string/test-strerror.c b/tools/regression/lib/libc/string/test-strerror.c index f5274ed..ffc1633 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); -- cgit v1.1