summaryrefslogtreecommitdiffstats
path: root/lib/libc/string
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1999-05-18 04:48:58 +0000
committerpeter <peter@FreeBSD.org>1999-05-18 04:48:58 +0000
commit91cb63bd8223191ce6a215de17a443593f687017 (patch)
treeca6b84ed415b795714421da075acf2dec7728934 /lib/libc/string
parent1d5521a97728c89e833a1b1790e8d9f257cf6206 (diff)
downloadFreeBSD-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/libc/string')
-rw-r--r--lib/libc/string/Makefile.inc5
-rw-r--r--lib/libc/string/strsignal.c72
2 files changed, 75 insertions, 2 deletions
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);
+}
OpenPOWER on IntegriCloud