* 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>
+
+ 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.
#include <locale.h>
#include <errno.h>
+#include <stdlib.h>
#include <string.h>
#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
, { 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++)
{
{
int saved_errno = errno;
freelocale (base_copy);
+ free (base_name);
errno = saved_errno;
return NULL;
}
}
}
+ free (base_name);
return base_copy;
}