Make unistd.h pre-c((-safe.
[glibc.git] / stdio-common / psignal.c
blobc8111051b122ffca897123cdc44f7a99f9403719
1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004, 2005, 2009
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 /* Defined in sys_siglist.c. */
28 extern const char *const _sys_siglist[];
29 extern const char *const _sys_siglist_internal[] attribute_hidden;
32 /* Print out on stderr a line consisting of the test in S, a colon, a space,
33 a message describing the meaning of the signal number SIG and a newline.
34 If S is NULL or "", the colon and space are omitted. */
35 void
36 psignal (int sig, const char *s)
38 const char *colon, *desc;
40 if (s == NULL || *s == '\0')
41 s = colon = "";
42 else
43 colon = ": ";
45 if (sig >= 0 && sig < NSIG && (desc = INTUSE(_sys_siglist)[sig]) != NULL)
46 (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _(desc));
47 else
49 char *buf;
51 if (__asprintf (&buf, _("%s%sUnknown signal %d\n"), s, colon, sig) < 0)
52 (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _("Unknown signal"));
53 else
55 (void) __fxprintf (NULL, "%s", buf);
57 free (buf);