diff options
author | peter <peter@FreeBSD.org> | 1999-05-18 04:48:58 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1999-05-18 04:48:58 +0000 |
commit | 91cb63bd8223191ce6a215de17a443593f687017 (patch) | |
tree | ca6b84ed415b795714421da075acf2dec7728934 /lib | |
parent | 1d5521a97728c89e833a1b1790e8d9f257cf6206 (diff) | |
download | FreeBSD-src-91cb63bd8223191ce6a215de17a443593f687017.zip FreeBSD-src-91cb63bd8223191ce6a215de17a443593f687017.tar.gz |
Add a strsignal(3) (like strerror(3)) for libc compatability with other
systems. NetBSD, Linux, SVR4 etc all have it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/psignal.3 | 23 | ||||
-rw-r--r-- | lib/libc/gen/siglist.c | 1 | ||||
-rw-r--r-- | lib/libc/string/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc/string/strsignal.c | 72 |
4 files changed, 95 insertions, 6 deletions
diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3 index aa78732..0018c8a 100644 --- a/lib/libc/gen/psignal.3 +++ b/lib/libc/gen/psignal.3 @@ -36,6 +36,7 @@ .Os BSD 4.2 .Sh NAME .Nm psignal , +.Nm strsignal , .Nm sys_siglist , .Nm sys_signame .Nd system signal messages @@ -43,16 +44,29 @@ .Fd #include <signal.h> .Ft void .Fn psignal "unsigned sig" "const char *s" +.Ft "char *" +.Fn strsignal "unsigned sig" .Vt extern const char * const sys_siglist[]; .Vt extern const char * const sys_signame[]; .Sh DESCRIPTION The .Fn psignal -function locates the descriptive message -string for the given signal number +and +.Fn strsignal +functions locate the descriptive message +string for a signal number. +.Pp +The +.Fn strsignal +function accepts a signal number argument .Fa sig -and writes it to the standard error. +and returns a pointer to the corresponding message string. .Pp +The +.Fn psignal +function accepts an signal number argument +.Fa sig +and writes it to the standard error. If the argument .Fa s is @@ -86,7 +100,8 @@ and .Va sys_signame . .Sh SEE ALSO .Xr sigaction 2 , -.Xr perror 3 +.Xr perror 3 , +.Xr strerror 3 .Sh HISTORY The .Fn psignal diff --git a/lib/libc/gen/siglist.c b/lib/libc/gen/siglist.c index be6334d..e6987d5 100644 --- a/lib/libc/gen/siglist.c +++ b/lib/libc/gen/siglist.c @@ -107,3 +107,4 @@ const char *const sys_siglist[NSIG] = { "User defined signal 1", /* SIGUSR1 */ "User defined signal 2" /* SIGUSR2 */ }; +const int sys_nsig = sizeof(sys_siglist) / sizeof(sys_siglist[0]); diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 42c8c39..2defef1 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,5 +1,5 @@ # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $Id: Makefile.inc,v 1.14 1998/02/20 08:23:55 jb Exp $ +# $Id: Makefile.inc,v 1.15 1999/01/19 23:45:48 jdp Exp $ .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/string ${.CURDIR}/../libc/string @@ -10,7 +10,7 @@ MISRCS+=bcmp.c bcopy.c bzero.c ffs.c index.c memccpy.c memchr.c memcmp.c \ memcpy.c memmove.c memset.c rindex.c strcasecmp.c strcat.c strchr.c \ strcmp.c strcoll.c strcpy.c strcspn.c strdup.c strerror.c strlen.c \ strmode.c strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strsep.c \ - strspn.c strstr.c strtok.c strxfrm.c swab.c + strsignal.c strspn.c strstr.c strtok.c strxfrm.c swab.c # machine-dependent string sources .include "${.CURDIR}/../libc/${MACHINE_ARCH}/string/Makefile.inc" @@ -27,5 +27,6 @@ MLINKS+=strcat.3 strncat.3 MLINKS+=strcmp.3 strncmp.3 MLINKS+=strcpy.3 strncpy.3 MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3 +MLINKS+=psignal.3 strsignal.3 psignal.3 sys_siglist.3 psignal.3 sys_signame.3 MLINKS+=strtok.3 strtok_r.3 .endif diff --git a/lib/libc/string/strsignal.c b/lib/libc/string/strsignal.c new file mode 100644 index 0000000..5ec6365 --- /dev/null +++ b/lib/libc/string/strsignal.c @@ -0,0 +1,72 @@ +/* + * 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. + * 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[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <stdio.h> +#include <string.h> +#include <signal.h> + +char * +strsignal(num) + int num; +{ +#define UPREFIX "Unknown signal: " + static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ + register unsigned int signum; + register char *p, *t; + char tmp[40]; + + signum = num; /* convert to unsigned */ + if (signum < sys_nsig) + return ((char *)sys_siglist[signum]); + + /* Do this by hand, so we don't link to stdio(3). */ + t = tmp; + if (num < 0) + signum = -signum; + do { + *t++ = "0123456789"[signum % 10]; + } while (signum /= 10); + if (num < 0) + *t++ = '-'; + for (p = ebuf + sizeof(UPREFIX) - 1;;) { + *p++ = *--t; + if (t <= tmp) + break; + } + *p = '\0'; + return (ebuf); +} |