Back to index

glibc  2.9
psignal.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004, 2005
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stdio.h>
00021 #include <signal.h>
00022 #include <stdlib.h>
00023 #include <libintl.h>
00024 #include <wchar.h>
00025 
00026 
00027 /* Defined in sys_siglist.c.  */
00028 extern const char *const _sys_siglist[];
00029 extern const char *const _sys_siglist_internal[] attribute_hidden;
00030 
00031 
00032 /* Print out on stderr a line consisting of the test in S, a colon, a space,
00033    a message describing the meaning of the signal number SIG and a newline.
00034    If S is NULL or "", the colon and space are omitted.  */
00035 void
00036 psignal (int sig, const char *s)
00037 {
00038   const char *colon, *desc;
00039 
00040   if (s == NULL || s == '\0')
00041     s = colon = "";
00042   else
00043     colon = ": ";
00044 
00045   if (sig >= 0 && sig < NSIG && (desc = INTUSE(_sys_siglist)[sig]) != NULL)
00046     (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _(desc));
00047   else
00048     {
00049       char *buf;
00050 
00051       if (__asprintf (&buf, _("%s%sUnknown signal %d\n"), s, colon, sig) < 0)
00052        (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _("Unknown signal"));
00053       else
00054        {
00055          (void) __fxprintf (NULL, "%s", buf);
00056 
00057          free (buf);
00058        }
00059     }
00060 }