2005-07-28 Thomas Schwinge <schwinge@nic-nac-project.de>
[glibc.git] / stdio-common / psignal.c
blobbe9509535053b588ef52de8fab3a504c6fc8f326
1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004, 2005
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stdio.h>
21 #include <signal.h>
22 #include <stdlib.h>
23 #include <libintl.h>
24 #include <wchar.h>
27 #ifndef HAVE_GNU_LD
28 #define _sys_siglist sys_siglist
29 #endif
31 /* Defined in sys_siglist.c. */
32 extern const char *const _sys_siglist[];
33 extern const char *const _sys_siglist_internal[] attribute_hidden;
36 /* Print out on stderr a line consisting of the test in S, a colon, a space,
37 a message describing the meaning of the signal number SIG and a newline.
38 If S is NULL or "", the colon and space are omitted. */
39 void
40 psignal (int sig, const char *s)
42 const char *colon, *desc;
44 if (s == NULL || s == '\0')
45 s = colon = "";
46 else
47 colon = ": ";
49 if (sig >= 0 && sig < NSIG && (desc = INTUSE(_sys_siglist)[sig]) != NULL)
50 (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _(desc));
51 else
53 char *buf;
55 if (__asprintf (&buf, _("%s%sUnknown signal %d\n"), s, colon, sig) < 0)
56 (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _("Unknown signal"));
57 else
59 (void) __fxprintf (NULL, "%s", buf);
61 free (buf);