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.
This commit is contained in:
parent
2a790909ba
commit
473c152a0a
@ -1,5 +1,5 @@
|
||||
# from: @(#)Makefile.inc 5.7 (Berkeley) 6/27/91
|
||||
# $Id: Makefile.inc,v 1.2 1993/08/01 05:40:44 mycroft Exp $
|
||||
# $Id: Makefile.inc,v 1.3 1993/10/07 19:28:46 jtc Exp $
|
||||
|
||||
# stdio sources
|
||||
.PATH: ${.CURDIR}/stdio
|
||||
@ -16,8 +16,8 @@ SRCS+= clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \
|
||||
wbuf.c wsetup.c
|
||||
|
||||
MAN3+= fclose.0 ferror.0 fflush.0 fgetline.0 fgets.0 fopen.0 fputs.0 \
|
||||
fread.0 fseek.0 funopen.0 getc.0 mktemp.0 printf.0 putc.0 remove.0 \
|
||||
scanf.0 setbuf.0 stdio.0 strerror.0 tmpnam.0 ungetc.0
|
||||
fread.0 fseek.0 funopen.0 getc.0 mktemp.0 perror.0 printf.0 putc.0 \
|
||||
remove.0 scanf.0 setbuf.0 stdio.0 tmpnam.0 ungetc.0
|
||||
|
||||
MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
|
||||
MLINKS+=fflush.3 fpurge.3
|
||||
@ -36,5 +36,4 @@ MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3
|
||||
MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
|
||||
scanf.3 vsscanf.3
|
||||
MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
|
||||
MLINKS+=strerror.3 perror.3
|
||||
MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3
|
||||
|
82
lib/libc/stdio/perror.3
Normal file
82
lib/libc/stdio/perror.3
Normal file
@ -0,0 +1,82 @@
|
||||
.\" 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: perror.3,v 1.1 1993/10/07 19:28:48 jtc Exp $
|
||||
.\"
|
||||
.Dd June 29, 1991
|
||||
.Dt PERROR 3
|
||||
.Os BSD 4
|
||||
.Sh NAME
|
||||
.Nm perror
|
||||
.Nd write error messages to standard error
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <stdio.h>
|
||||
.Ft void
|
||||
.Fn perror "const char *string"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn perror
|
||||
function looks up the language-dependant error message string affiliated
|
||||
with an error number and writes it, followed by a new-line, to the
|
||||
standard error stream.
|
||||
.Pp
|
||||
If the argument
|
||||
.Fa string
|
||||
is
|
||||
.Pf non- Dv NULL
|
||||
it is prepended to the message string and separated from it by
|
||||
a colon and a space
|
||||
.Pq Ql \&:\ \& .
|
||||
If
|
||||
.Fa string
|
||||
is
|
||||
.Dv NULL
|
||||
only the error message string is printed.
|
||||
.Pp
|
||||
The contents of the error message string is the same as those returned by
|
||||
.Fn strerror
|
||||
with argument
|
||||
.Fa errno .
|
||||
.Sh SEE ALSO
|
||||
.Xr intro 2 ,
|
||||
.Xr psignal 3 ,
|
||||
.Xr setlocale 3 ,
|
||||
.Xr strerror 3 ,
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn perror
|
||||
function conforms to
|
||||
.St -ansiC .
|
@ -33,7 +33,7 @@
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
/*static char *sccsid = "from: @(#)perror.c 5.11 (Berkeley) 2/24/91";*/
|
||||
static char *rcsid = "$Id: perror.c,v 1.3 1993/08/26 00:47:10 jtc Exp $";
|
||||
static char *rcsid = "$Id: perror.c,v 1.4 1993/10/07 19:28:49 jtc Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -43,12 +43,21 @@ static char *rcsid = "$Id: perror.c,v 1.3 1993/08/26 00:47:10 jtc Exp $";
|
||||
#include <stdio.h>
|
||||
#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().
|
||||
*/
|
||||
|
||||
extern char *_strerror __P((int , char *));
|
||||
|
||||
void
|
||||
perror(s)
|
||||
const char *s;
|
||||
{
|
||||
register struct iovec *v;
|
||||
struct iovec iov[4];
|
||||
static char buf[40];
|
||||
|
||||
v = iov;
|
||||
if (s && *s) {
|
||||
@ -59,7 +68,7 @@ perror(s)
|
||||
v->iov_len = 2;
|
||||
v++;
|
||||
}
|
||||
v->iov_base = strerror(errno);
|
||||
v->iov_base = _strerror(errno, buf);
|
||||
v->iov_len = strlen(v->iov_base);
|
||||
v++;
|
||||
v->iov_base = "\n";
|
||||
|
@ -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
|
||||
|
67
lib/libc/string/strerror.3
Normal file
67
lib/libc/string/strerror.3
Normal file
@ -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 .
|
86
lib/libc/string/strerror.c
Normal file
86
lib/libc/string/strerror.c
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user