diff options
author | Bruno Haible <bruno@clisp.org> | 2019-12-12 17:52:50 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-12-12 17:52:50 +0100 |
commit | fbfc2664030502c0cad8ba1ff6d8d328e3843509 (patch) | |
tree | 83d39c99da0a61d04d1bcd3f2ee42e518be650ff /lib/duplocale.c | |
parent | ea54538a0eba9cefa8c17cda35527fa5a77a5098 (diff) | |
download | gnulib-fbfc2664030502c0cad8ba1ff6d8d328e3843509.tar.gz |
duplocale: Fix test failure on AIX 7.2 with xlclang.
* lib/duplocale.c: Include <stdlib.h>.
(rpl_duplocale): Use a heap-allocated copy of the first setlocale return
value.
Diffstat (limited to 'lib/duplocale.c')
-rw-r--r-- | lib/duplocale.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/duplocale.c b/lib/duplocale.c index eaecf8cb44..3b958bab51 100644 --- a/lib/duplocale.c +++ b/lib/duplocale.c @@ -22,6 +22,7 @@ #include <locale.h> #include <errno.h> +#include <stdlib.h> #include <string.h> #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) @@ -67,14 +68,21 @@ rpl_duplocale (locale_t locale) , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK } #endif }; - const char *base_name; + char *base_name; locale_t base_copy; unsigned int i; - base_name = setlocale (LC_CTYPE, NULL); + base_name = strdup (setlocale (LC_CTYPE, NULL)); + if (base_name == NULL) + return NULL; base_copy = newlocale (LC_ALL_MASK, base_name, NULL); if (base_copy == NULL) - return NULL; + { + int saved_errno = errno; + free (base_name); + errno = saved_errno; + return NULL; + } for (i = 0; i < SIZEOF (categories); i++) { @@ -88,6 +96,7 @@ rpl_duplocale (locale_t locale) { int saved_errno = errno; freelocale (base_copy); + free (base_name); errno = saved_errno; return NULL; } @@ -97,6 +106,7 @@ rpl_duplocale (locale_t locale) } } + free (base_name); return base_copy; } |