aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wemm <peter@FreeBSD.org>1999-05-18 04:48:58 +0000
committerPeter Wemm <peter@FreeBSD.org>1999-05-18 04:48:58 +0000
commit78121e79aa390b2e94fb8aca2d0477d81aa20cf2 (patch)
treea7da280e9c51ddf3723fc804ad191a284f8d89a0
parentb1334ec97da48be7ae393b95f60d139a16e6fc6a (diff)
downloadsrc-78121e79aa390b2e94fb8aca2d0477d81aa20cf2.tar.gz
src-78121e79aa390b2e94fb8aca2d0477d81aa20cf2.zip
Add a strsignal(3) (like strerror(3)) for libc compatability with other
systems. NetBSD, Linux, SVR4 etc all have it.
Notes
Notes: svn path=/head/; revision=47289
-rw-r--r--include/signal.h1
-rw-r--r--include/string.h1
-rw-r--r--lib/libc/gen/psignal.323
-rw-r--r--lib/libc/gen/siglist.c1
-rw-r--r--lib/libc/string/Makefile.inc5
-rw-r--r--lib/libc/string/strsignal.c72
6 files changed, 97 insertions, 6 deletions
diff --git a/include/signal.h b/include/signal.h
index cba3a4461efd..69832e068d1e 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -44,6 +44,7 @@
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
extern __const char *__const sys_signame[NSIG];
extern __const char *__const sys_siglist[NSIG];
+extern __const int sys_nsig;
#endif
__BEGIN_DECLS
diff --git a/include/string.h b/include/string.h
index acfebfc7141a..56997677af4c 100644
--- a/include/string.h
+++ b/include/string.h
@@ -86,6 +86,7 @@ char *strdup __P((const char *));
void strmode __P((int, char *));
int strncasecmp __P((const char *, const char *, size_t));
char *strsep __P((char **, const char *));
+char *strsignal __P((int));
char *strtok_r __P((char *, const char *, char **));
void swab __P((const void *, void *, size_t));
#endif
diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3
index aa78732d55ae..0018c8a7c981 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 be6334dd4055..e6987d5795d0 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 42c8c39944c1..2defef1dcc26 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 000000000000..5ec6365fbd93
--- /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);
+}