1 /* Copyright (C) 1991-2013 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>
25 static __libc_key_t key
;
27 /* If nonzero the key allocation failed and we should better use a
28 static buffer than fail. */
30 static char local_buf
[BUFFERSIZ
];
31 static char *static_buf
;
33 /* Destructor for the thread-specific data. */
34 static void init (void);
35 static void free_key_mem (void *mem
);
36 static char *getbuffer (void);
39 /* Return a string describing the meaning of the signal number SIGNUM. */
41 strsignal (int signum
)
43 __libc_once_define (static, once
);
46 /* If we have not yet initialized the buffer do it now. */
47 __libc_once (once
, init
);
51 (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
) ||
53 signum
< 0 || signum
>= NSIG
54 || (desc
= _sys_siglist
[signum
]) == NULL
)
56 char *buffer
= getbuffer ();
59 if (signum
>= SIGRTMIN
&& signum
<= SIGRTMAX
)
60 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Real-time signal %d"),
64 len
= __snprintf (buffer
, BUFFERSIZ
- 1, _("Unknown signal %d"),
74 return (char *) _(desc
);
78 /* Initialize buffer. */
82 if (__libc_key_create (&key
, free_key_mem
))
83 /* Creating the key failed. This means something really went
84 wrong. In any case use a static buffer which is better than
86 static_buf
= local_buf
;
90 /* Free the thread specific data, this is done if a thread terminates. */
92 free_key_mem (void *mem
)
95 __libc_setspecific (key
, NULL
);
99 /* Return the buffer to be used. */
105 if (static_buf
!= NULL
)
109 /* We don't use the static buffer and so we have a key. Use it
110 to get the thread-specific buffer. */
111 result
= __libc_getspecific (key
);
114 /* No buffer allocated so far. */
115 result
= malloc (BUFFERSIZ
);
117 /* No more memory available. We use the static buffer. */
120 __libc_setspecific (key
, result
);