From owner-svn-src-all@FreeBSD.ORG Tue Apr 5 21:56:05 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C992B1065676; Tue, 5 Apr 2011 21:56:05 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B88198FC18; Tue, 5 Apr 2011 21:56:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p35Lu5dx031819; Tue, 5 Apr 2011 21:56:05 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p35Lu5uN031814; Tue, 5 Apr 2011 21:56:05 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201104052156.p35Lu5uN031814@svn.freebsd.org> From: Jilles Tjoelker Date: Tue, 5 Apr 2011 21:56:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220376 - in head: lib/libc/gen lib/libc/string tools/regression/lib/libc/string X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2011 21:56:06 -0000 Author: jilles Date: Tue Apr 5 21:56:05 2011 New Revision: 220376 URL: http://svn.freebsd.org/changeset/base/220376 Log: 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 Modified: head/lib/libc/gen/errlst.c head/lib/libc/string/strerror.3 head/lib/libc/string/strerror.c head/tools/regression/lib/libc/string/test-strerror.c Modified: head/lib/libc/gen/errlst.c ============================================================================== --- head/lib/libc/gen/errlst.c Tue Apr 5 21:55:43 2011 (r220375) +++ head/lib/libc/gen/errlst.c Tue Apr 5 21:56:05 2011 (r220376) @@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$"); #include 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 */ Modified: head/lib/libc/string/strerror.3 ============================================================================== --- head/lib/libc/string/strerror.3 Tue Apr 5 21:55:43 2011 (r220375) +++ head/lib/libc/string/strerror.3 Tue Apr 5 21:56:05 2011 (r220376) @@ -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 Modified: head/lib/libc/string/strerror.c ============================================================================== --- head/lib/libc/string/strerror.c Tue Apr 5 21:55:43 2011 (r220375) +++ head/lib/libc/string/strerror.c Tue Apr 5 21:56:05 2011 (r220376) @@ -87,7 +87,7 @@ strerror_r(int errnum, char *strerrbuf, 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), Modified: head/tools/regression/lib/libc/string/test-strerror.c ============================================================================== --- head/tools/regression/lib/libc/string/test-strerror.c Tue Apr 5 21:55:43 2011 (r220375) +++ head/tools/regression/lib/libc/string/test-strerror.c Tue Apr 5 21:56:05 2011 (r220376) @@ -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);