diff options
| author | jtc <jtc@NetBSD.org> | 1993-10-07 19:27:50 +0000 |
|---|---|---|
| committer | jtc <jtc@NetBSD.org> | 1993-10-07 19:27:50 +0000 |
| commit | 473c152a0a82be0bb0b0a28762c4ac9150aca0ea (patch) | |
| tree | 10b94a6513f456f3619d89ba344102e5ad66e8b9 /lib/libc/string | |
| parent | 2a790909ba821cb5cd8625b449071b83645c985c (diff) | |
Moved strerror.[c3] from libc/stdio to libc/string.
Since perror is not permitted to change strerror()'s static buffer, I have
changed both functions to pass their own buffers to the new library-internal
function _strerror() that actually does the error message string look up.
Split strerror manpage into strerror and perror manpages.
Diffstat (limited to 'lib/libc/string')
| -rw-r--r-- | lib/libc/string/Makefile.inc | 6 | ||||
| -rw-r--r-- | lib/libc/string/strerror.3 | 67 | ||||
| -rw-r--r-- | lib/libc/string/strerror.c | 86 |
3 files changed, 156 insertions, 3 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 8467343879c..cbd3d8413be 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,10 +1,10 @@ # from: @(#)Makefile.inc 5.6 (Berkeley) 3/5/91 -# $Id: Makefile.inc,v 1.12 1993/10/07 00:24:09 cgd Exp $ +# $Id: Makefile.inc,v 1.13 1993/10/07 19:27:50 jtc Exp $ # string sources .PATH: ${.CURDIR}/arch/${MACHINE}/string ${.CURDIR}/string -SRCS+= memccpy.c strcasecmp.c strcoll.c strdup.c \ +SRCS+= memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ strftime.c strmode.c strtok.c strxfrm.c .if (${MACHINE} == "hp300") @@ -102,7 +102,7 @@ MAN3+= bcmp.0 bcopy.0 bstring.0 bzero.0 ffs.0 index.0 memccpy.0 memchr.0 \ memcmp.0 memcpy.0 memmove.0 memset.0 rindex.0 strcasecmp.0 strcat.0 \ strchr.0 strcmp.0 strcoll.0 strcpy.0 strcspn.0 strftime.0 string.0 \ strlen.0 strmode.0 strdup.0 strpbrk.0 strrchr.0 strsep.0 strspn.0 \ - strstr.0 strtok.0 strxfrm.0 swab.0 + strstr.0 strtok.0 strxfrm.0 strerror.0 swab.0 MLINKS+=strcasecmp.3 strncasecmp.3 MLINKS+=strcat.3 strncat.3 diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3 new file mode 100644 index 00000000000..6b8752a654e --- /dev/null +++ b/lib/libc/string/strerror.3 @@ -0,0 +1,67 @@ +.\" Copyright (c) 1980, 1991 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. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 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. +.\" +.\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91 +.\" $Id: strerror.3,v 1.1 1993/10/07 19:27:52 jtc Exp $ +.\" +.Dd June 29, 1991 +.Dt STRERROR 3 +.Os BSD 4 +.Sh NAME +.Nm strerror +.Nd system error messages +.Sh SYNOPSIS +.Fd #include <string.h> +.Ft char * +.Fn strerror "int errnum" +.Sh DESCRIPTION +The +.Fn strerror +function returns a pointer to the language-dependant error message string +affiliated with an error number. +.Pp +The array pointed to is not to be modified by the program, but may be +overwritten by subsequent calls to +.Fn strerror . +.Sh SEE ALSO +.Xr intro 2 , +.Xr perror 3 , +.Xr setlocale 3 , +.Xr sys_errlist 3 +.Sh STANDARDS +The +.Fn strerror +function conforms to +.St -ansiC . diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c new file mode 100644 index 00000000000..905ebbf4d2c --- /dev/null +++ b/lib/libc/string/strerror.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1988 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 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 = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ +static char *rcsid = "$Id: strerror.c,v 1.1 1993/10/07 19:27:53 jtc Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <string.h> + +/* + * Since perror() is not allowed to change the contents of strerror()'s + * static buffer, both functions supply their own buffers to the + * internal function _strerror(). + */ + +char * +_strerror(num, buf) + int num; + char *buf; +{ +#define UPREFIX "Unknown error: " + extern char *sys_errlist[]; + extern int sys_nerr; + register unsigned int errnum; + register char *p, *t; + char tmp[40]; + + errnum = num; /* convert to unsigned */ + if (errnum < sys_nerr) + return(sys_errlist[errnum]); + + /* Do this by hand, so we don't include stdio(3). */ + t = tmp; + do { + *t++ = "0123456789"[errnum % 10]; + } while (errnum /= 10); + + strcpy (buf, UPREFIX); + for (p = buf + sizeof(UPREFIX) -1;;) { + *p++ = *--t; + if (t <= tmp) + break; + } + + return buf; +} + + +char * +strerror(num) + int num; +{ + static char buf[40]; /* 64-bit number + slop */ + return _strerror(num, buf); +} |
