1 /* Copyright (C) 1991, 1994-2002, 2005 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include <bits/libc-lock.h>
27 /* Defined in siglist.c. */
28 extern const char *const _sys_siglist
[];
29 extern const char *const _sys_siglist_internal
[] attribute_hidden
;
30 static __libc_key_t key
;
32 /* If nonzero the key allocation failed and we should better use a
33 static buffer than fail. */
35 static char local_buf
[BUFFERSIZ
];
36 static char *static_buf
;
38 /* Destructor for the thread-specific data. */
39 static void init (void);
40 static void free_key_mem (void *mem
);
41 static char *getbuffer (void);
44 /* Return a string describing the meaning of the signal number SIGNUM. */
46 strsignal (int signum
)
48 __libc_once_define (static, once
);
51 /* If we have not yet initialized the buffer do it now. */
52 __libc_once (once
, init
);
56 (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
) ||
58 signum
< 0 || signum
>= NSIG
59 || (desc
= INTUSE(_sys_siglist
)[signum
]) == NULL
)
61 char *buffer
= getbuffer ();
64 if (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
)
65 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Real-time signal %d"),
69 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Unknown signal %d"),
79 return (char *) _(desc
);
83 /* Initialize buffer. */
87 if (__libc_key_create (&key
, free_key_mem
))
88 /* Creating the key failed. This means something really went
89 wrong. In any case use a static buffer which is better than
91 static_buf
= local_buf
;
95 /* Free the thread specific data, this is done if a thread terminates. */
97 free_key_mem (void *mem
)
100 __libc_setspecific (key
, NULL
);
104 /* Return the buffer to be used. */
110 if (static_buf
!= NULL
)
114 /* We don't use the static buffer and so we have a key. Use it
115 to get the thread-specific buffer. */
116 result
= __libc_getspecific (key
);
119 /* No buffer allocated so far. */
120 result
= malloc (BUFFERSIZ
);
122 /* No more memory available. We use the static buffer. */
125 __libc_setspecific (key
, result
);