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 ();
65 if (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
)
66 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Real-time signal %d"),
70 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Unknown signal %d"),
80 return (char *) _(desc
);
84 /* Initialize buffer. */
88 if (__libc_key_create (&key
, free_key_mem
))
89 /* Creating the key failed. This means something really went
90 wrong. In any case use a static buffer which is better than
92 static_buf
= local_buf
;
96 /* Free the thread specific data, this is done if a thread terminates. */
98 free_key_mem (void *mem
)
101 __libc_setspecific (key
, NULL
);
105 /* Return the buffer to be used. */
111 if (static_buf
!= NULL
)
115 /* We don't use the static buffer and so we have a key. Use it
116 to get the thread-specific buffer. */
117 result
= __libc_getspecific (key
);
120 /* No buffer allocated so far. */
121 result
= malloc (BUFFERSIZ
);
123 /* No more memory available. We use the static buffer. */
126 __libc_setspecific (key
, result
);