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, see
16 <http://www.gnu.org/licenses/>. */
23 #include <bits/libc-lock.h>
26 /* Defined in siglist.c. */
27 extern const char *const _sys_siglist
[];
28 extern const char *const _sys_siglist_internal
[] attribute_hidden
;
29 static __libc_key_t key
;
31 /* If nonzero the key allocation failed and we should better use a
32 static buffer than fail. */
34 static char local_buf
[BUFFERSIZ
];
35 static char *static_buf
;
37 /* Destructor for the thread-specific data. */
38 static void init (void);
39 static void free_key_mem (void *mem
);
40 static char *getbuffer (void);
43 /* Return a string describing the meaning of the signal number SIGNUM. */
45 strsignal (int signum
)
47 __libc_once_define (static, once
);
50 /* If we have not yet initialized the buffer do it now. */
51 __libc_once (once
, init
);
55 (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
) ||
57 signum
< 0 || signum
>= NSIG
58 || (desc
= INTUSE(_sys_siglist
)[signum
]) == NULL
)
60 char *buffer
= getbuffer ();
63 if (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
)
64 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Real-time signal %d"),
68 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Unknown signal %d"),
78 return (char *) _(desc
);
82 /* Initialize buffer. */
86 if (__libc_key_create (&key
, free_key_mem
))
87 /* Creating the key failed. This means something really went
88 wrong. In any case use a static buffer which is better than
90 static_buf
= local_buf
;
94 /* Free the thread specific data, this is done if a thread terminates. */
96 free_key_mem (void *mem
)
99 __libc_setspecific (key
, NULL
);
103 /* Return the buffer to be used. */
109 if (static_buf
!= NULL
)
113 /* We don't use the static buffer and so we have a key. Use it
114 to get the thread-specific buffer. */
115 result
= __libc_getspecific (key
);
118 /* No buffer allocated so far. */
119 result
= malloc (BUFFERSIZ
);
121 /* No more memory available. We use the static buffer. */
124 __libc_setspecific (key
, result
);