Index: stable/8/lib/libc/gen/errlst.c =================================================================== --- stable/8/lib/libc/gen/errlst.c (revision 220663) +++ stable/8/lib/libc/gen/errlst.c (revision 220664) @@ -1,155 +1,155 @@ /* * Copyright (c) 1982, 1985, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)errlst.c 8.2 (Berkeley) 11/16/93"; #endif /* LIBC_SCCS and not lint */ #include __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 */ "Interrupted system call", /* 4 - EINTR */ "Input/output error", /* 5 - EIO */ "Device not configured", /* 6 - ENXIO */ "Argument list too long", /* 7 - E2BIG */ "Exec format error", /* 8 - ENOEXEC */ "Bad file descriptor", /* 9 - EBADF */ "No child processes", /* 10 - ECHILD */ "Resource deadlock avoided", /* 11 - EDEADLK */ "Cannot allocate memory", /* 12 - ENOMEM */ "Permission denied", /* 13 - EACCES */ "Bad address", /* 14 - EFAULT */ "Block device required", /* 15 - ENOTBLK */ "Device busy", /* 16 - EBUSY */ "File exists", /* 17 - EEXIST */ "Cross-device link", /* 18 - EXDEV */ "Operation not supported by device", /* 19 - ENODEV */ "Not a directory", /* 20 - ENOTDIR */ "Is a directory", /* 21 - EISDIR */ "Invalid argument", /* 22 - EINVAL */ "Too many open files in system", /* 23 - ENFILE */ "Too many open files", /* 24 - EMFILE */ "Inappropriate ioctl for device", /* 25 - ENOTTY */ "Text file busy", /* 26 - ETXTBSY */ "File too large", /* 27 - EFBIG */ "No space left on device", /* 28 - ENOSPC */ "Illegal seek", /* 29 - ESPIPE */ "Read-only file system", /* 30 - EROFS */ "Too many links", /* 31 - EMLINK */ "Broken pipe", /* 32 - EPIPE */ /* math software */ "Numerical argument out of domain", /* 33 - EDOM */ "Result too large", /* 34 - ERANGE */ /* non-blocking and interrupt i/o */ "Resource temporarily unavailable", /* 35 - EAGAIN */ /* 35 - EWOULDBLOCK */ "Operation now in progress", /* 36 - EINPROGRESS */ "Operation already in progress", /* 37 - EALREADY */ /* ipc/network software -- argument errors */ "Socket operation on non-socket", /* 38 - ENOTSOCK */ "Destination address required", /* 39 - EDESTADDRREQ */ "Message too long", /* 40 - EMSGSIZE */ "Protocol wrong type for socket", /* 41 - EPROTOTYPE */ "Protocol not available", /* 42 - ENOPROTOOPT */ "Protocol not supported", /* 43 - EPROTONOSUPPORT */ "Socket type not supported", /* 44 - ESOCKTNOSUPPORT */ "Operation not supported", /* 45 - EOPNOTSUPP */ "Protocol family not supported", /* 46 - EPFNOSUPPORT */ /* 47 - EAFNOSUPPORT */ "Address family not supported by protocol family", "Address already in use", /* 48 - EADDRINUSE */ "Can't assign requested address", /* 49 - EADDRNOTAVAIL */ /* ipc/network software -- operational errors */ "Network is down", /* 50 - ENETDOWN */ "Network is unreachable", /* 51 - ENETUNREACH */ "Network dropped connection on reset", /* 52 - ENETRESET */ "Software caused connection abort", /* 53 - ECONNABORTED */ "Connection reset by peer", /* 54 - ECONNRESET */ "No buffer space available", /* 55 - ENOBUFS */ "Socket is already connected", /* 56 - EISCONN */ "Socket is not connected", /* 57 - ENOTCONN */ "Can't send after socket shutdown", /* 58 - ESHUTDOWN */ "Too many references: can't splice", /* 59 - ETOOMANYREFS */ "Operation timed out", /* 60 - ETIMEDOUT */ "Connection refused", /* 61 - ECONNREFUSED */ "Too many levels of symbolic links", /* 62 - ELOOP */ "File name too long", /* 63 - ENAMETOOLONG */ /* should be rearranged */ "Host is down", /* 64 - EHOSTDOWN */ "No route to host", /* 65 - EHOSTUNREACH */ "Directory not empty", /* 66 - ENOTEMPTY */ /* quotas & mush */ "Too many processes", /* 67 - EPROCLIM */ "Too many users", /* 68 - EUSERS */ "Disc quota exceeded", /* 69 - EDQUOT */ /* Network File System */ "Stale NFS file handle", /* 70 - ESTALE */ "Too many levels of remote in path", /* 71 - EREMOTE */ "RPC struct is bad", /* 72 - EBADRPC */ "RPC version wrong", /* 73 - ERPCMISMATCH */ "RPC prog. not avail", /* 74 - EPROGUNAVAIL */ "Program version wrong", /* 75 - EPROGMISMATCH */ "Bad procedure for program", /* 76 - EPROCUNAVAIL */ "No locks available", /* 77 - ENOLCK */ "Function not implemented", /* 78 - ENOSYS */ "Inappropriate file type or format", /* 79 - EFTYPE */ "Authentication error", /* 80 - EAUTH */ "Need authenticator", /* 81 - ENEEDAUTH */ "Identifier removed", /* 82 - EIDRM */ "No message of desired type", /* 83 - ENOMSG */ "Value too large to be stored in data type", /* 84 - EOVERFLOW */ "Operation canceled", /* 85 - ECANCELED */ "Illegal byte sequence", /* 86 - EILSEQ */ "Attribute not found", /* 87 - ENOATTR */ /* General */ "Programming error", /* 88 - EDOOFUS */ "Bad message", /* 89 - EBADMSG */ "Multihop attempted", /* 90 - EMULTIHOP */ "Link has been severed", /* 91 - ENOLINK */ "Protocol error", /* 92 - EPROTO */ "Capabilities insufficient", /* 93 - ENOTCAPABLE */ }; const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]); Index: stable/8/lib/libc/stdtime =================================================================== --- stable/8/lib/libc/stdtime (revision 220663) +++ stable/8/lib/libc/stdtime (revision 220664) Property changes on: stable/8/lib/libc/stdtime ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/lib/libc/stdtime:r220376 Index: stable/8/lib/libc/string/strerror.3 =================================================================== --- stable/8/lib/libc/string/strerror.3 (revision 220663) +++ stable/8/lib/libc/string/strerror.3 (revision 220664) @@ -1,186 +1,189 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the American National Standards Committee X3, on Information .\" Processing Systems. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)strerror.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd October 12, 2004 +.Dd April 5, 2011 .Dt STRERROR 3 .Os .Sh NAME .Nm perror , .Nm strerror , .Nm strerror_r , .Nm sys_errlist , .Nm sys_nerr .Nd system error messages .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdio.h .Ft void .Fn perror "const char *string" .Vt extern const char * const sys_errlist[] ; .Vt extern const int sys_nerr ; .In string.h .Ft "char *" .Fn strerror "int errnum" .Ft int .Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen" .Sh DESCRIPTION The .Fn strerror , .Fn strerror_r and .Fn perror functions look up the error message string corresponding to an error number. .Pp The .Fn strerror function accepts an error number argument .Fa errnum and returns a pointer to the corresponding message string. .Pp The .Fn strerror_r function renders the same result into .Fa strerrbuf for a maximum of .Fa buflen characters and returns 0 upon success. .Pp The .Fn perror function finds the error message corresponding to the current value of the global variable .Va errno .Pq Xr intro 2 and writes it, followed by a newline, to the standard error file descriptor. If the argument .Fa string is .Pf non- Dv NULL and does not point to the null character, this string is prepended to the message string and separated from it by a colon and space .Pq Dq Li ":\ " ; otherwise, only the error message string is printed. .Pp If the error number is not recognized, these functions return an error message string containing .Dq Li "Unknown error:\ " followed by the error number in decimal. The .Fn strerror and .Fn strerror_r functions return .Er EINVAL as a warning. Error numbers recognized by this implementation fall in 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 (as specified in .Fa buflen ) to contain the error string, .Fn strerror_r returns .Er ERANGE and .Fa strerrbuf will contain an error message that has been truncated and .Dv NUL terminated to fit the length specified by .Fa buflen . .Pp The message strings can be accessed directly using the external array .Va sys_errlist . The external value .Va sys_nerr contains a count of the messages in .Va sys_errlist . The use of these variables is deprecated; .Fn strerror or .Fn strerror_r should be used instead. .Sh SEE ALSO .Xr intro 2 , .Xr psignal 3 .Sh STANDARDS The .Fn perror and .Fn strerror functions conform to .St -isoC-99 . The .Fn strerror_r function conforms to .St -p1003.1-2001 . .Sh HISTORY The .Fn strerror and .Fn perror functions first appeared in .Bx 4.4 . The .Fn strerror_r function was implemented in .Fx 4.4 by .An Wes Peters Aq wes@FreeBSD.org . .Sh BUGS For unknown error numbers, the .Fn strerror function will return its result in a static buffer which may be overwritten by subsequent calls. .Pp The return type for .Fn strerror is missing a type-qualifier; it should actually be .Vt const char * . .Pp Programs that use the deprecated .Va sys_errlist variable often fail to compile because they declare it inconsistently. Index: stable/8/lib/libc/string/strerror.c =================================================================== --- stable/8/lib/libc/string/strerror.c (revision 220663) +++ stable/8/lib/libc/string/strerror.c (revision 220664) @@ -1,126 +1,126 @@ /*- * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #if defined(NLS) #include #endif #include #include #include #include #define UPREFIX "Unknown error" /* * Define a buffer size big enough to describe a 64-bit signed integer * converted to ASCII decimal (19 bytes), with an optional leading sign * (1 byte); finally, we get the prefix, delimiter (": ") and a trailing * NUL from UPREFIX. */ #define EBUFSIZE (20 + 2 + sizeof(UPREFIX)) /* * Doing this by hand instead of linking with stdio(3) avoids bloat for * statically linked binaries. */ static void errstr(int num, char *uprefix, char *buf, size_t len) { char *t; unsigned int uerr; char tmp[EBUFSIZE]; t = tmp + sizeof(tmp); *--t = '\0'; uerr = (num >= 0) ? num : -num; do { *--t = "0123456789"[uerr % 10]; } while (uerr /= 10); if (num < 0) *--t = '-'; *--t = ' '; *--t = ':'; strlcpy(buf, uprefix, len); strlcat(buf, t, len); } int strerror_r(int errnum, char *strerrbuf, size_t buflen) { int retval = 0; #if defined(NLS) int saved_errno = errno; nl_catd catd; 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), #else UPREFIX, #endif strerrbuf, buflen); retval = EINVAL; } else { if (strlcpy(strerrbuf, #if defined(NLS) catgets(catd, 1, errnum, sys_errlist[errnum]), #else sys_errlist[errnum], #endif buflen) >= buflen) retval = ERANGE; } #if defined(NLS) catclose(catd); errno = saved_errno; #endif return (retval); } char * strerror(int num) { static char ebuf[NL_TEXTMAX]; if (strerror_r(num, ebuf, sizeof(ebuf)) != 0) errno = EINVAL; return (ebuf); } Index: stable/8/lib/libc =================================================================== --- stable/8/lib/libc (revision 220663) +++ stable/8/lib/libc (revision 220664) Property changes on: stable/8/lib/libc ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/lib/libc:r220376 Index: stable/8/tools/regression/lib/libc/string/test-strerror.c =================================================================== --- stable/8/tools/regression/lib/libc/string/test-strerror.c (revision 220663) +++ stable/8/tools/regression/lib/libc/string/test-strerror.c (revision 220664) @@ -1,130 +1,135 @@ /*- * Copyright (c) 2001 Wes Peters * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include int main(void) { char buf[64]; 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); ok1(errno == EINVAL); /* * 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); errno = 0; sret = strerror(EPFNOSUPPORT); ok1(strcmp(sret, "Protocol family not supported") == 0); ok1(errno == 0); errno = 0; sret = strerror(ELAST); ok1(errno == 0); /* * 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)); /* One byte too short. */ iret = strerror_r(EPERM, buf, strlen("Operation not permitted")); ok1(strcmp(buf, "Operation not permitte") == 0); ok1(iret == ERANGE); memset(buf, '*', sizeof(buf)); /* One byte too short. */ iret = strerror_r(-1, buf, strlen("Unknown error: -1")); ok1(strcmp(buf, "Unknown error: -") == 0); ok1(iret == EINVAL); memset(buf, '*', sizeof(buf)); /* Two bytes too short. */ iret = strerror_r(-2, buf, strlen("Unknown error: -2") - 1); ok1(strcmp(buf, "Unknown error: ") == 0); ok1(iret == EINVAL); memset(buf, '*', sizeof(buf)); /* Three bytes too short. */ iret = strerror_r(-2, buf, strlen("Unknown error: -2") - 2); ok1(strcmp(buf, "Unknown error:") == 0); ok1(iret == EINVAL); memset(buf, '*', sizeof(buf)); /* One byte too short. */ iret = strerror_r(12345, buf, strlen("Unknown error: 12345")); ok1(strcmp(buf, "Unknown error: 1234") == 0); ok1(iret == EINVAL); /* * 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); memset(buf, '*', sizeof(buf)); iret = strerror_r(EPROCLIM, buf, sizeof(buf)); ok1(strcmp(buf, "Too many processes") == 0); ok1(iret == 0); return exit_status(); } Index: stable/8/tools/regression/lib/libc =================================================================== --- stable/8/tools/regression/lib/libc (revision 220663) +++ stable/8/tools/regression/lib/libc (revision 220664) Property changes on: stable/8/tools/regression/lib/libc ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/tools/regression/lib/libc:r220376