1 /* Copyright (C) 1991,94,95,96,97,98,99,2000 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. */
24 #include <bits/libc-lock.h>
28 #define _sys_siglist sys_siglist
31 /* Defined in siglist.c. */
32 extern const char *const _sys_siglist[];
33 static __libc_key_t key;
35 /* If nonzero the key allocation failed and we should better use a
36 static buffer than fail. */
38 static char local_buf[BUFFERSIZ];
39 static char *static_buf;
41 /* Destructor for the thread-specific data. */
42 static void init (void);
43 static void free_key_mem (void *mem);
44 static char *getbuffer (void);
47 /* Return a string describing the meaning of the signal number SIGNUM. */
49 strsignal (int signum)
51 __libc_once_define (static, once);
54 /* If we have not yet initialized the buffer do it now. */
55 __libc_once (once, init);
59 (signum >= SIGRTMIN && signum <= SIGRTMAX) ||
61 signum < 0 || signum >= NSIG || (desc = _sys_siglist[signum]) == NULL)
63 char *buffer = getbuffer ();
66 if (signum >= SIGRTMIN && signum <= SIGRTMAX)
67 len = __snprintf (buffer, BUFFERSIZ - 1, _("Real-time signal %d"),
71 len = __snprintf (buffer, BUFFERSIZ - 1, _("Unknown signal %d"),
81 return (char *) _(desc);
85 /* Initialize buffer. */
89 if (__libc_key_create (&key, free_key_mem))
90 /* Creating the key failed. This means something really went
91 wrong. In any case use a static buffer which is better than
93 static_buf = local_buf;
97 /* Free the thread specific data, this is done if a thread terminates. */
99 free_key_mem (void *mem)
102 __libc_setspecific (key, NULL);
106 /* Return the buffer to be used. */
112 if (static_buf != NULL)
116 /* We don't use the static buffer and so we have a key. Use it
117 to get the thread-specific buffer. */
118 result = __libc_getspecific (key);
121 /* No buffer allocated so far. */
122 result = malloc (BUFFERSIZ);
124 /* No more memory available. We use the static buffer. */
127 __libc_setspecific (key, result);
140 text_set_element (__libc_subfreeres, free_mem);