Updated to fedora-glibc-20041218T1131
[glibc.git] / stdio-common / psignal.c
blob2e6588c6925b977b8c4b7b02e69428f20bf6c5b1
1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004
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)
51 if (_IO_fwide (stderr, 0) > 0)
52 (void) __fwprintf (stderr, L"%s%s%s\n", s, colon, _(desc));
53 else
54 (void) fprintf (stderr, "%s%s%s\n", s, colon, _(desc));
56 else
58 char *buf;
60 if (__asprintf (&buf, _("%s%sUnknown signal %d\n"), s, colon, sig) < 0)
62 if (_IO_fwide (stderr, 0) > 0)
63 (void) __fwprintf (stderr, L"%s%s%s\n", s, colon, _("Unknown signal"));
64 else
65 (void) fprintf (stderr, "%s%s%s\n", s, colon, _("Unknown signal"));
67 else
69 if (_IO_fwide (stderr, 0) > 0)
70 (void) __fwprintf (stderr, L"%s", buf);
71 else
72 (void) fputs (buf, stderr);
74 free (buf);