Add a strsignal(3) (like strerror(3)) for libc compatability with other

systems. NetBSD, Linux, SVR4 etc all have it.
This commit is contained in:
Peter Wemm 1999-05-18 04:48:58 +00:00
parent b1334ec97d
commit 78121e79aa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=47289
6 changed files with 97 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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 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.
.Pp
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

View File

@ -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]);

View File

@ -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

View File

@ -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);
}