summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-12-12 17:52:50 +0100
committerBruno Haible <bruno@clisp.org>2019-12-12 17:52:50 +0100
commitfbfc2664030502c0cad8ba1ff6d8d328e3843509 (patch)
tree83d39c99da0a61d04d1bcd3f2ee42e518be650ff
parentea54538a0eba9cefa8c17cda35527fa5a77a5098 (diff)
downloadgnulib-fbfc2664030502c0cad8ba1ff6d8d328e3843509.tar.gz
gnulib-fbfc2664030502c0cad8ba1ff6d8d328e3843509.tar.bz2
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.
-rw-r--r--ChangeLog7
-rw-r--r--lib/duplocale.c16
2 files changed, 20 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index edbcab28e2..6f4f764de7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2019-12-12 Bruno Haible <bruno@clisp.org>
+ 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.
+
+2019-12-12 Bruno Haible <bruno@clisp.org>
+
stddef: Document the AIX xlc issue.
* doc/posix-headers/stddef.texi: Document the NULL issue with AIX xlc.
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;
}

Return to:

Send suggestions and report system problems to the System administrator.