diff options
| author | jtc <jtc@NetBSD.org> | 1994-09-03 05:07:49 +0000 |
|---|---|---|
| committer | jtc <jtc@NetBSD.org> | 1994-09-03 05:07:49 +0000 |
| commit | 6d3bf399eb3a53578aabdf5c201532964867c17c (patch) | |
| tree | 9d9fe5dce65fbc1df43256e0a2ba0343801aa321 /lib/libc/string | |
| parent | 5281a6457b9b62a43cb610b6b58e55ded8eaae0c (diff) | |
__strerror() and __strsignal() have been broken out into their own files
and use message catalogs if NLS is defined.
Increased the size of char buffers used by strerror() and strsignal();
the error and signal strings may be much longer in some locales.
Diffstat (limited to 'lib/libc/string')
| -rw-r--r-- | lib/libc/string/Makefile.inc | 5 | ||||
| -rw-r--r-- | lib/libc/string/__strerror.c | 86 | ||||
| -rw-r--r-- | lib/libc/string/__strsignal.c | 81 | ||||
| -rw-r--r-- | lib/libc/string/strerror.c | 37 | ||||
| -rw-r--r-- | lib/libc/string/strsignal.c | 16 |
5 files changed, 178 insertions, 47 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 05eb461c6b7..5dfd1b681fa 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,11 +1,12 @@ # from: @(#)Makefile.inc 5.6 (Berkeley) 3/5/91 -# $Id: Makefile.inc,v 1.29 1994/08/02 05:01:20 jtc Exp $ +# $Id: Makefile.inc,v 1.30 1994/09/03 05:07:49 jtc Exp $ # string sources .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/string ${.CURDIR}/string SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ - strftime.c strmode.c strsignal.c strtok.c strxfrm.c + strftime.c strmode.c strsignal.c strtok.c strxfrm.c \ + __strerror.c __strsignal.c .if (${MACHINE_ARCH} == "m68k") SRCS+= bcmp.S bcopy.S bzero.S ffs.S index.S memchr.c memcmp.S memset.S \ diff --git a/lib/libc/string/__strerror.c b/lib/libc/string/__strerror.c new file mode 100644 index 00000000000..b637ff0f87e --- /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 1994/09/03 05:07:51 jtc Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <string.h> +#ifdef NLS +#include <nl_types.h> +#endif + +/* + * 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 *sys_errlist[]; +extern int sys_nerr; + +char * +__strerror(num, buf) + int num; + char *buf; +{ +#define UPREFIX "Unknown error: %u" + register unsigned int errnum; + +#ifdef NLS + nl_catd catd ; + catd = catopen("libc", 0); +#endif + + errnum = num; /* convert to unsigned */ + if (errnum < sys_nerr) { +#ifdef NLS + strcpy(buf, catgets(catd, 1, errnum, sys_errlist[errnum])); +#else + return(sys_errlist[errnum]); +#endif + } else { +#ifdef NLS + sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); +#else + sprintf(buf, UPREFIX, errnum); +#endif + } + +#ifdef NLS + catclose(catd); +#endif + + return buf; +} diff --git a/lib/libc/string/__strsignal.c b/lib/libc/string/__strsignal.c new file mode 100644 index 00000000000..3b781e6239d --- /dev/null +++ b/lib/libc/string/__strsignal.c @@ -0,0 +1,81 @@ +/* + * 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: __strsignal.c,v 1.1 1994/09/03 05:07:52 jtc Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <signal.h> +#include <string.h> +#ifdef NLS +#include <nl_types.h> +#endif + +extern char *sys_siglist[]; +extern int sys_nerr; + +char * +__strsignal(num, buf) + int num; + char *buf; +{ +#define UPREFIX "Unknown signal: %u" + register unsigned int signum; + +#ifdef NLS + nl_catd catd ; + catd = catopen("libc", 0); +#endif + + signum = num; /* convert to unsigned */ + if (signum < NSIG) { +#ifdef NLS + strcpy(buf, catgets(catd, 2, signum, sys_siglist[signum])); +#else + return(sys_siglist[signum]); +#endif + } else { +#ifdef NLS + sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), signum); +#else + sprintf(buf, UPREFIX, signum); +#endif + } + +#ifdef NLS + catclose(catd); +#endif + + return buf; +} diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index 125cdd2c689..6db1f92f893 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -33,7 +33,7 @@ #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.2 1993/10/09 00:11:01 jtc Exp $"; +static char *rcsid = "$Id: strerror.c,v 1.3 1994/09/03 05:07:53 jtc Exp $"; #endif /* LIBC_SCCS and not lint */ #include <string.h> @@ -44,43 +44,12 @@ static char *rcsid = "$Id: strerror.c,v 1.2 1993/10/09 00:11:01 jtc Exp $"; * 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; -} - +extern char *__strerror __P((int, char *)); char * strerror(num) int num; { - static char buf[40]; /* 64-bit number + slop */ + static char buf[128]; return __strerror(num, buf); } diff --git a/lib/libc/string/strsignal.c b/lib/libc/string/strsignal.c index 3bc86be4ace..15478e90a2f 100644 --- a/lib/libc/string/strsignal.c +++ b/lib/libc/string/strsignal.c @@ -33,23 +33,17 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ -static char *rcsid = "$Id: strsignal.c,v 1.1 1994/08/02 05:01:23 jtc Exp $"; +static char *rcsid = "$Id: strsignal.c,v 1.2 1994/09/03 05:07:56 jtc Exp $"; #endif /* LIBC_SCCS and not lint */ #include <string.h> -#include <signal.h> + +extern char *__strsignal __P((int, char *)); char * strsignal(sig) int sig; { - unsigned int signum = sig; - static char buf[40]; - - if (signum < NSIG) { - return(sys_siglist[signum]); - } - - sprintf(buf, "Unknown signal: %d", signum); - return buf; + static char buf[128]; + return __strsignal(sig, buf); } |
