]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 2007-2019 Free Software Foundation, Inc. |
4a44ce79 UD |
2 | This file is part of the GNU C Library. |
3 | ||
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. | |
8 | ||
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. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
4a44ce79 UD |
17 | |
18 | #include <libintl.h> | |
19 | #include <locale.h> | |
20 | #include <stdio.h> | |
965cba04 | 21 | #include <stdlib.h> |
4a44ce79 UD |
22 | #include <string.h> |
23 | #include <sys/param.h> | |
2827ab99 | 24 | #include <libc-symbols.h> |
4a44ce79 UD |
25 | |
26 | static __thread char *last_value; | |
27 | ||
28 | ||
29 | static const char * | |
30 | translate (const char *str, locale_t loc) | |
31 | { | |
32 | locale_t oldloc = __uselocale (loc); | |
33 | const char *res = _(str); | |
34 | __uselocale (oldloc); | |
35 | return res; | |
36 | } | |
37 | ||
38 | ||
39 | /* Return a string describing the errno code in ERRNUM. */ | |
40 | char * | |
41 | strerror_l (int errnum, locale_t loc) | |
42 | { | |
43 | ||
44 | ||
45 | if (__builtin_expect (errnum < 0 || errnum >= _sys_nerr_internal | |
46 | || _sys_errlist_internal[errnum] == NULL, 0)) | |
47 | { | |
48 | free (last_value); | |
49 | if (__asprintf (&last_value, "%s%d", | |
50 | translate ("Unknown error ", loc), errnum) == -1) | |
51 | last_value = NULL; | |
52 | ||
53 | return last_value; | |
54 | } | |
55 | ||
56 | return (char *) translate (_sys_errlist_internal[errnum], loc); | |
57 | } | |
58 | ||
124e0258 FW |
59 | void |
60 | __strerror_thread_freeres (void) | |
4a44ce79 UD |
61 | { |
62 | free (last_value); | |
63 | } | |
124e0258 | 64 | text_set_element (__libc_subfreeres, __strerror_thread_freeres); |