diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2020-05-14 17:56:25 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2020-07-07 14:10:58 -0300 |
commit | 725eeb4af14c6fec4ed26a796cdfd6d50df86d42 (patch) | |
tree | d42f43a268e498d3ff8a891ef274747e4f2a0795 /sysdeps/mach/strerror_l.c | |
parent | 28aff047818eb1726394296d27b9c7885340bead (diff) | |
download | glibc-725eeb4af14c6fec4ed26a796cdfd6d50df86d42.tar.gz glibc-725eeb4af14c6fec4ed26a796cdfd6d50df86d42.tar.xz glibc-725eeb4af14c6fec4ed26a796cdfd6d50df86d42.zip |
string: Use tls-internal on strerror_l
The buffer allocation uses the same strategy of strsignal. Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, and s390x-linux-gnu. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'sysdeps/mach/strerror_l.c')
-rw-r--r-- | sysdeps/mach/strerror_l.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c index b6c9fdbe80..72b857f4a0 100644 --- a/sysdeps/mach/strerror_l.c +++ b/sysdeps/mach/strerror_l.c @@ -23,11 +23,7 @@ #include <string.h> #include <mach/error.h> #include <errorlib.h> -#include <sys/param.h> -#include <libc-symbols.h> - - -static __thread char *last_value; +#include <tls-internal.h> static const char * @@ -58,13 +54,14 @@ __strerror_l (int errnum, locale_t loc) if (system > err_max_system || ! __mach_error_systems[system].bad_sub) { - free (last_value); - if (__asprintf (&last_value, "%s%X", + struct tls_internal_t *tls_internal = __glibc_tls_internal (); + free (tls_internal->strerror_l_buf); + if (__asprintf (&tls_internal->strerror_l_buf, "%s%X", translate ("Error in unknown error system: ", loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - return last_value; + return tls_internal->strerror_l_buf; } es = &__mach_error_systems[system]; @@ -74,25 +71,18 @@ __strerror_l (int errnum, locale_t loc) if (code >= es->subsystem[sub].max_code) { - free (last_value); - if (__asprintf (&last_value, "%s%s %d", + struct tls_internal_t *tls_internal = __glibc_tls_internal (); + free (tls_internal->strerror_l_buf); + if (__asprintf (&tls_internal->strerror_l_buf, "%s%s %d", translate ("Unknown error ", loc), translate (es->subsystem[sub].subsys_name, loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - return last_value; + return tls_internal->strerror_l_buf; } return (char *) translate (es->subsystem[sub].codes[code], loc); } weak_alias (__strerror_l, strerror_l) libc_hidden_def (__strerror_l) - -/* This is called when a thread is exiting to free the last_value string. */ -void -__strerror_thread_freeres (void) -{ - free (last_value); -} -text_set_element (__libc_subfreeres, __strerror_thread_freeres); |