1 /* Copyright (C) 1991, 1994-2000, 2001, 2002 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>
28 #define _sys_siglist sys_siglist
31 /* Defined in siglist.c. */
32 extern const char *const _sys_siglist
[];
33 extern const char *const _sys_siglist_internal
[] attribute_hidden
;
34 static __libc_key_t key
;
36 /* If nonzero the key allocation failed and we should better use a
37 static buffer than fail. */
39 static char local_buf
[BUFFERSIZ
];
40 static char *static_buf
;
42 /* Destructor for the thread-specific data. */
43 static void init (void);
44 static void free_key_mem (void *mem
);
45 static char *getbuffer (void);
48 /* Return a string describing the meaning of the signal number SIGNUM. */
50 strsignal (int signum
)
52 __libc_once_define (static, once
);
55 /* If we have not yet initialized the buffer do it now. */
56 __libc_once (once
, init
);
60 (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
) ||
62 signum
< 0 || signum
>= NSIG
63 || (desc
= INTUSE(_sys_siglist
)[signum
]) == NULL
)
65 char *buffer
= getbuffer ();
68 if (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
)
69 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Real-time signal %d"),
73 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Unknown signal %d"),
83 return (char *) _(desc
);
87 /* Initialize buffer. */
91 if (__libc_key_create (&key
, free_key_mem
))
92 /* Creating the key failed. This means something really went
93 wrong. In any case use a static buffer which is better than
95 static_buf
= local_buf
;
99 /* Free the thread specific data, this is done if a thread terminates. */
101 free_key_mem (void *mem
)
104 __libc_setspecific (key
, NULL
);
108 /* Return the buffer to be used. */
114 if (static_buf
!= NULL
)
118 /* We don't use the static buffer and so we have a key. Use it
119 to get the thread-specific buffer. */
120 result
= __libc_getspecific (key
);
123 /* No buffer allocated so far. */
124 result
= malloc (BUFFERSIZ
);
126 /* No more memory available. We use the static buffer. */
129 __libc_setspecific (key
, result
);