1 /* Copyright (C) 1991, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
23 #include <bits/libc-lock.h>
27 #define _sys_siglist sys_siglist
30 /* Defined in siglist.c. */
31 extern const char *const _sys_siglist[];
32 static __libc_key_t key;
34 /* If nonzero the key allocation failed and we should better use a
35 static buffer than fail. */
37 static char local_buf[BUFFERSIZ];
38 static char *static_buf;
40 /* Destructor for the thread-specific data. */
41 static void init (void);
42 static void free_key_mem (void *mem);
43 static char *getbuffer (void);
46 /* Return a string describing the meaning of the signal number SIGNUM. */
48 strsignal (int signum)
50 __libc_once_define (static, once);
53 /* If we have not yet initialized the buffer do it now. */
54 __libc_once (once, init);
58 (signum >= SIGRTMIN && signum <= SIGRTMAX) ||
60 signum < 0 || signum >= NSIG || (desc = _sys_siglist[signum]) == NULL)
62 char *buffer = getbuffer ();
63 int len = __snprintf (buffer, BUFFERSIZ - 1,
65 signum >= SIGRTMIN && signum <= SIGRTMAX
66 ? _("Real-time signal %d") :
68 _("Unknown signal %d"), signum);
77 return (char *) _(desc);
81 /* Initialize buffer. */
85 if (__libc_key_create (&key, free_key_mem))
86 /* Creating the key failed. This means something really went
87 wrong. In any case use a static buffer which is better than
89 static_buf = local_buf;
93 /* Free the thread specific data, this is done if a thread terminates. */
95 free_key_mem (void *mem)
98 __libc_setspecific (key, NULL);
102 /* Return the buffer to be used. */
108 if (static_buf != NULL)
112 /* We don't use the static buffer and so we have a key. Use it
113 to get the thread-specific buffer. */
114 result = __libc_getspecific (key);
117 /* No buffer allocated so far. */
118 result = malloc (BUFFERSIZ);
120 /* No more memory available. We use the static buffer. */
123 __libc_setspecific (key, result);