Commit 505092c2 authored by Bruno Haible's avatar Bruno Haible
Browse files

setlocale: Make calls with NULL argument multithread-safe.

* lib/setlocale.c: Include <errno.h>.
(setlocale_mtsafe): New function.
(setlocale_unixlike): Invoke setlocale_mtsafe instead of setlocale.
(setlocale_improved): Renamed from rpl_setlocale.
* m4/setlocale.m4 (gl_FUNC_SETLOCALE): Require gl_FUNC_SETLOCALE_NULL.
Set and define NEED_SETLOCALE_IMPROVED and NEED_SETLOCALE_MTSAFE. Set
LIB_SETLOCALE.
* modules/setlocale (Depends-on): Add setlocale-null. Update conditions.
(Link): New section.
* tests/locale.c: Undefine setlocale.
* tests/test-setlocale_null-one.c: Likewise.
* tests/test-setlocale_null-all.c: Likewise.
* modules/setlocale-tests (Makefile.am): Link the test programs with
$(LIB_SETLOCALE).
* modules/astrxfrm-tests (Makefile.am): Likewise.
* modules/btowc-tests (Makefile.am): Likewise.
* modules/c-ctype-tests (Makefile.am): Likewise.
* modules/c-snprintf-tests (Makefile.am): Likewise.
* modules/c-strcase-tests (Makefile.am): Likewise.
* modules/c-vasprintf-tests (Makefile.am): Likewise.
* modules/c-vsnprintf-tests (Makefile.am): Likewise.
* modules/c-xvasprintf-tests (Makefile.am): Likewise.
* modules/dfa-tests (Makefile.am): Likewise.
* modules/duplocale-tests (Makefile.am): Likewise.
* modules/hard-locale-tests (Makefile.am): Likewise.
* modules/localcharset-tests (Makefile.am): Likewise.
* modules/localename-tests (Makefile.am): Likewise.
* modules/mbmemcasecmp-tests (Makefile.am): Likewise.
* modules/mbmemcasecoll-tests (Makefile.am): Likewise.
* modules/mbrtowc-tests (Makefile.am): Likewise.
* modules/mbscasecmp-tests (Makefile.am): Likewise.
* modules/mbscasestr-tests (Makefile.am): Likewise.
* modules/mbschr-tests (Makefile.am): Likewise.
* modules/mbscspn-tests (Makefile.am): Likewise.
* modules/mbsinit-tests (Makefile.am): Likewise.
* modules/mbsncasecmp-tests (Makefile.am): Likewise.
* modules/mbsnrtowcs-tests (Makefile.am): Likewise.
* modules/mbspbrk-tests (Makefile.am): Likewise.
* modules/mbspcasecmp-tests (Makefile.am): Likewise.
* modules/mbsrchr-tests (Makefile.am): Likewise.
* modules/mbsrtowcs-tests (Makefile.am): Likewise.
* modules/mbsspn-tests (Makefile.am): Likewise.
* modules/mbsstr-tests (Makefile.am): Likewise.
* modules/nl_langinfo-tests (Makefile.am): Likewise.
* modules/quotearg-tests (Makefile.am): Likewise.
* modules/regex-tests (Makefile.am): Likewise.
* modules/strfmon_l-tests (Makefile.am): Likewise.
* modules/strtod-tests (Makefile.am): Likewise.
* modules/strtold-tests (Makefile.am): Likewise.
* modules/unicase/locale-language-tests (Makefile.am): Likewise.
* modules/unicase/ulc-casecmp-tests (Makefile.am): Likewise.
* modules/unicase/ulc-casecoll-tests (Makefile.am): Likewise.
* modules/unigbrk/ulc-grapheme-breaks-tests (Makefile.am): Likewise.
* modules/unistdio/u8-vasnprintf-tests (Makefile.am): Likewise.
* modules/unistdio/u16-vasnprintf-tests (Makefile.am): Likewise.
* modules/unistdio/u32-vasnprintf-tests (Makefile.am): Likewise.
* modules/unistdio/ulc-vasnprintf-tests (Makefile.am): Likewise.
* modules/uniwbrk/ulc-wordbreaks-tests (Makefile.am): Likewise.
* modules/vasnprintf-posix-tests (Makefile.am): Likewise.
* modules/wcrtomb-tests (Makefile.am): Likewise.
* modules/wcsnrtombs-tests (Makefile.am): Likewise.
* modules/wcsrtombs-tests (Makefile.am): Likewise.
* modules/wcwidth-tests (Makefile.am): Likewise.
* doc/posix-functions/setlocale.texi: Mention that the multithread-
safety fix is also available in module 'setlocale'.
parent 25d476a2
2019-12-18 Bruno Haible <bruno@clisp.org>
setlocale: Make calls with NULL argument multithread-safe.
* lib/setlocale.c: Include <errno.h>.
(setlocale_mtsafe): New function.
(setlocale_unixlike): Invoke setlocale_mtsafe instead of setlocale.
(setlocale_improved): Renamed from rpl_setlocale.
* m4/setlocale.m4 (gl_FUNC_SETLOCALE): Require gl_FUNC_SETLOCALE_NULL.
Set and define NEED_SETLOCALE_IMPROVED and NEED_SETLOCALE_MTSAFE. Set
LIB_SETLOCALE.
* modules/setlocale (Depends-on): Add setlocale-null. Update conditions.
(Link): New section.
* tests/locale.c: Undefine setlocale.
* tests/test-setlocale_null-one.c: Likewise.
* tests/test-setlocale_null-all.c: Likewise.
* modules/setlocale-tests (Makefile.am): Link the test programs with
$(LIB_SETLOCALE).
* modules/astrxfrm-tests (Makefile.am): Likewise.
* modules/btowc-tests (Makefile.am): Likewise.
* modules/c-ctype-tests (Makefile.am): Likewise.
* modules/c-snprintf-tests (Makefile.am): Likewise.
* modules/c-strcase-tests (Makefile.am): Likewise.
* modules/c-vasprintf-tests (Makefile.am): Likewise.
* modules/c-vsnprintf-tests (Makefile.am): Likewise.
* modules/c-xvasprintf-tests (Makefile.am): Likewise.
* modules/dfa-tests (Makefile.am): Likewise.
* modules/duplocale-tests (Makefile.am): Likewise.
* modules/hard-locale-tests (Makefile.am): Likewise.
* modules/localcharset-tests (Makefile.am): Likewise.
* modules/localename-tests (Makefile.am): Likewise.
* modules/mbmemcasecmp-tests (Makefile.am): Likewise.
* modules/mbmemcasecoll-tests (Makefile.am): Likewise.
* modules/mbrtowc-tests (Makefile.am): Likewise.
* modules/mbscasecmp-tests (Makefile.am): Likewise.
* modules/mbscasestr-tests (Makefile.am): Likewise.
* modules/mbschr-tests (Makefile.am): Likewise.
* modules/mbscspn-tests (Makefile.am): Likewise.
* modules/mbsinit-tests (Makefile.am): Likewise.
* modules/mbsncasecmp-tests (Makefile.am): Likewise.
* modules/mbsnrtowcs-tests (Makefile.am): Likewise.
* modules/mbspbrk-tests (Makefile.am): Likewise.
* modules/mbspcasecmp-tests (Makefile.am): Likewise.
* modules/mbsrchr-tests (Makefile.am): Likewise.
* modules/mbsrtowcs-tests (Makefile.am): Likewise.
* modules/mbsspn-tests (Makefile.am): Likewise.
* modules/mbsstr-tests (Makefile.am): Likewise.
* modules/nl_langinfo-tests (Makefile.am): Likewise.
* modules/quotearg-tests (Makefile.am): Likewise.
* modules/regex-tests (Makefile.am): Likewise.
* modules/strfmon_l-tests (Makefile.am): Likewise.
* modules/strtod-tests (Makefile.am): Likewise.
* modules/strtold-tests (Makefile.am): Likewise.
* modules/unicase/locale-language-tests (Makefile.am): Likewise.
* modules/unicase/ulc-casecmp-tests (Makefile.am): Likewise.
* modules/unicase/ulc-casecoll-tests (Makefile.am): Likewise.
* modules/unigbrk/ulc-grapheme-breaks-tests (Makefile.am): Likewise.
* modules/unistdio/u8-vasnprintf-tests (Makefile.am): Likewise.
* modules/unistdio/u16-vasnprintf-tests (Makefile.am): Likewise.
* modules/unistdio/u32-vasnprintf-tests (Makefile.am): Likewise.
* modules/unistdio/ulc-vasnprintf-tests (Makefile.am): Likewise.
* modules/uniwbrk/ulc-wordbreaks-tests (Makefile.am): Likewise.
* modules/vasnprintf-posix-tests (Makefile.am): Likewise.
* modules/wcrtomb-tests (Makefile.am): Likewise.
* modules/wcsnrtombs-tests (Makefile.am): Likewise.
* modules/wcsrtombs-tests (Makefile.am): Likewise.
* modules/wcwidth-tests (Makefile.am): Likewise.
* doc/posix-functions/setlocale.texi: Mention that the multithread-
safety fix is also available in module 'setlocale'.
2019-12-18 Bruno Haible <bruno@clisp.org>
 
hard-locale: Make multithread-safe.
......@@ -26,14 +26,15 @@ always fails. The replacement, however, supports only the locale names
@code{"C"} and @code{"POSIX"}.
@end itemize
Portability problems fixed by Gnulib module @code{setlocale-null}:
Portability problems fixed by Gnulib module @code{setlocale} or @code{setlocale-null}:
@itemize
@item
Invocations of @code{setlocale (..., NULL)} are not multithread-safe on some
platforms:
musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin.
To make these invocations multithread-safe, you need to change the code to
invoke @code{setlocale_null} instead.
To make these invocations multithread-safe, you need the Gnulib module
@code{setlocale}, or you need to change the code to invoke @code{setlocale_null}
instead.
@end itemize
Portability problems not fixed by Gnulib:
......
......@@ -29,6 +29,7 @@
/* Specification. */
#include <locale.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -51,6 +52,141 @@ extern void gl_locale_name_canonicalize (char *name);
# undef setlocale
/* Which of the replacements to activate? */
# if NEED_SETLOCALE_IMPROVED
# define setlocale_improved rpl_setlocale
# elif NEED_SETLOCALE_MTSAFE
# define setlocale_mtsafe rpl_setlocale
# else
# error "This file should only be compiled if NEED_SETLOCALE_IMPROVED || NEED_SETLOCALE_MTSAFE."
# endif
/* Like setlocale, but guaranteed to be multithread-safe if LOCALE == NULL. */
# if !SETLOCALE_NULL_ALL_MTSAFE || !SETLOCALE_NULL_ONE_MTSAFE /* i.e. if NEED_SETLOCALE_MTSAFE */
# if NEED_SETLOCALE_IMPROVED
static
# endif
char *
setlocale_mtsafe (int category, const char *locale)
{
if (locale == NULL)
{
/* This call must be multithread-safe. To achieve this without using
thread-local storage:
1. We use a specific static buffer for each possible CATEGORY
argument. So that different threads can call setlocale_mtsafe
with different CATEGORY arguments, without interfering.
2. We use a simple strcpy or memcpy to fill this static buffer.
Filling it through, for example, strcpy + strcat would not be
guaranteed to leave the buffer's contents intact if another thread
is currently accessing it. If necessary, the contents is first
assembled in a stack-allocated buffer. */
if (category == LC_ALL)
{
# if SETLOCALE_NULL_ALL_MTSAFE
return setlocale (LC_ALL, NULL);
# else
char buf[SETLOCALE_NULL_ALL_MAX];
static char resultbuf[SETLOCALE_NULL_ALL_MAX];
if (setlocale_null (LC_ALL, buf, sizeof (buf)))
return (char *) "C";
strcpy (resultbuf, buf);
return resultbuf;
# endif
}
else
{
# if SETLOCALE_NULL_ONE_MTSAFE
return setlocale (category, NULL);
# else
enum
{
LC_CTYPE_INDEX,
LC_NUMERIC_INDEX,
LC_TIME_INDEX,
LC_COLLATE_INDEX,
LC_MONETARY_INDEX,
LC_MESSAGES_INDEX,
# ifdef LC_PAPER
LC_PAPER_INDEX,
# endif
# ifdef LC_NAME
LC_NAME_INDEX,
# endif
# ifdef LC_ADDRESS
LC_ADDRESS_INDEX,
# endif
# ifdef LC_TELEPHONE
LC_TELEPHONE_INDEX,
# endif
# ifdef LC_MEASUREMENT
LC_MEASUREMENT_INDEX,
# endif
# ifdef LC_IDENTIFICATION
LC_IDENTIFICATION_INDEX,
# endif
LC_INDICES_COUNT
}
i;
char buf[SETLOCALE_NULL_MAX];
static char resultbuf[LC_INDICES_COUNT][SETLOCALE_NULL_MAX];
int err;
err = setlocale_null (category, buf, sizeof (buf));
if (err == EINVAL)
return NULL;
if (err)
return (char *) "C";
switch (category)
{
case LC_CTYPE: i = LC_CTYPE_INDEX; break;
case LC_NUMERIC: i = LC_NUMERIC_INDEX; break;
case LC_TIME: i = LC_TIME_INDEX; break;
case LC_COLLATE: i = LC_COLLATE_INDEX; break;
case LC_MONETARY: i = LC_MONETARY_INDEX; break;
case LC_MESSAGES: i = LC_MESSAGES_INDEX; break;
# ifdef LC_PAPER
case LC_PAPER: i = LC_PAPER_INDEX; break;
# endif
# ifdef LC_NAME
case LC_NAME: i = LC_NAME_INDEX; break;
# endif
# ifdef LC_ADDRESS
case LC_ADDRESS: i = LC_ADDRESS_INDEX; break;
# endif
# ifdef LC_TELEPHONE
case LC_TELEPHONE: i = LC_TELEPHONE_INDEX; break;
# endif
# ifdef LC_MEASUREMENT
case LC_MEASUREMENT: i = LC_MEASUREMENT_INDEX; break;
# endif
# ifdef LC_IDENTIFICATION
case LC_IDENTIFICATION: i = LC_IDENTIFICATION_INDEX; break;
# endif
default:
/* If you get here, a #ifdef LC_xxx is missing. */
abort ();
}
strcpy (resultbuf[i], buf);
return resultbuf[i];
# endif
}
}
else
return setlocale (category, locale);
}
# else /* !NEED_SETLOCALE_MTSAFE */
# define setlocale_mtsafe setlocale
# endif /* NEED_SETLOCALE_MTSAFE */
# if NEED_SETLOCALE_IMPROVED
/* Return string representation of locale category CATEGORY. */
static const char *
category_to_name (int category)
......@@ -85,7 +221,7 @@ category_to_name (int category)
return retval;
}
# if defined _WIN32 && ! defined __CYGWIN__
# if defined _WIN32 && ! defined __CYGWIN__
/* The native Windows setlocale() function expects locale names of the form
"German" or "German_Germany" or "DEU", but not "de" or "de_DE". We need
......@@ -652,7 +788,7 @@ setlocale_unixlike (int category, const char *locale)
locale = "C";
/* First, try setlocale with the original argument unchanged. */
result = setlocale (category, locale);
result = setlocale_mtsafe (category, locale);
if (result != NULL)
return result;
......@@ -794,13 +930,13 @@ setlocale_unixlike (int category, const char *locale)
return NULL;
}
# elif defined __ANDROID__
# elif defined __ANDROID__
/* Like setlocale, but accept also the locale names "C" and "POSIX". */
static char *
setlocale_unixlike (int category, const char *locale)
{
char *result = setlocale (category, locale);
char *result = setlocale_mtsafe (category, locale);
if (result == NULL)
switch (category)
{
......@@ -825,13 +961,13 @@ setlocale_unixlike (int category, const char *locale)
}
return result;
}
# define setlocale setlocale_unixlike
# define setlocale setlocale_unixlike
# else
# define setlocale_unixlike setlocale
# endif
# else
# define setlocale_unixlike setlocale_mtsafe
# endif
# if LC_MESSAGES == 1729
# if LC_MESSAGES == 1729
/* The system does not store an LC_MESSAGES locale category. Do it here. */
static char lc_messages_name[64] = "C";
......@@ -853,11 +989,11 @@ setlocale_single (int category, const char *locale)
return setlocale_unixlike (category, locale);
}
# else
# define setlocale_single setlocale_unixlike
# endif
# else
# define setlocale_single setlocale_unixlike
# endif
# if defined __APPLE__ && defined __MACH__
# if defined __APPLE__ && defined __MACH__
/* Mapping from language to main territory where that language is spoken. */
static char const locales_with_principal_territory[][6 + 1] =
......@@ -1115,7 +1251,7 @@ langcmp (const char *locale1, const char *locale2)
static const char *
get_main_locale_with_same_language (const char *locale)
{
# define table locales_with_principal_territory
# define table locales_with_principal_territory
/* The table is sorted. Perform a binary search. */
size_t hi = sizeof (table) / sizeof (table[0]);
size_t lo = 0;
......@@ -1142,7 +1278,7 @@ get_main_locale_with_same_language (const char *locale)
return table[mid];
}
}
# undef table
# undef table
return NULL;
}
......@@ -1344,7 +1480,7 @@ get_main_locale_with_same_territory (const char *locale)
{
if (strrchr (locale, '_') != NULL)
{
# define table locales_with_principal_language
# define table locales_with_principal_language
/* The table is sorted. Perform a binary search. */
size_t hi = sizeof (table) / sizeof (table[0]);
size_t lo = 0;
......@@ -1371,15 +1507,15 @@ get_main_locale_with_same_territory (const char *locale)
return table[mid];
}
}
# undef table
# undef table
}
return NULL;
}
# endif
# endif
char *
rpl_setlocale (int category, const char *locale)
setlocale_improved (int category, const char *locale)
{
if (locale != NULL && locale[0] == '\0')
{
......@@ -1431,14 +1567,14 @@ rpl_setlocale (int category, const char *locale)
goto fail;
i = 0;
}
# if defined _WIN32 && ! defined __CYGWIN__
# if defined _WIN32 && ! defined __CYGWIN__
/* On native Windows, setlocale(LC_ALL,...) may succeed but set the
LC_CTYPE category to an invalid value ("C") when it does not
support the specified encoding. Report a failure instead. */
if (strchr (base_name, '.') != NULL
&& strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
goto fail;
# endif
# endif
for (; i < sizeof (categories) / sizeof (categories[0]); i++)
{
......@@ -1452,12 +1588,12 @@ rpl_setlocale (int category, const char *locale)
/* If name is the same as base_name, it has already been set
through the setlocale call before the loop. */
if (strcmp (name, base_name) != 0
# if LC_MESSAGES == 1729
# if LC_MESSAGES == 1729
|| cat == LC_MESSAGES
# endif
# endif
)
if (setlocale_single (cat, name) == NULL)
# if defined __APPLE__ && defined __MACH__
# if defined __APPLE__ && defined __MACH__
{
/* On Mac OS X 10.13, some locales can be set through
System Preferences > Language & Region, that are not
......@@ -1473,11 +1609,11 @@ rpl_setlocale (int category, const char *locale)
warn = (setlocale_single (cat, "UTF-8") == NULL);
else if (cat == LC_MESSAGES)
{
# if HAVE_CFLOCALECOPYPREFERREDLANGUAGES || HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.4 or newer */
# if HAVE_CFLOCALECOPYPREFERREDLANGUAGES || HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.4 or newer */
/* Take the primary language preference. */
# if HAVE_CFLOCALECOPYPREFERREDLANGUAGES /* MacOS X 10.5 or newer */
# if HAVE_CFLOCALECOPYPREFERREDLANGUAGES /* MacOS X 10.5 or newer */
CFArrayRef prefArray = CFLocaleCopyPreferredLanguages ();
# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.4 or newer */
# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.4 or newer */
CFTypeRef preferences =
CFPreferencesCopyAppValue (CFSTR ("AppleLanguages"),
kCFPreferencesCurrentApplication);
......@@ -1485,7 +1621,7 @@ rpl_setlocale (int category, const char *locale)
&& CFGetTypeID (preferences) == CFArrayGetTypeID ())
{
CFArrayRef prefArray = (CFArrayRef)preferences;
# endif
# endif
int n = CFArrayGetCount (prefArray);
if (n > 0)
{
......@@ -1519,19 +1655,19 @@ rpl_setlocale (int category, const char *locale)
}
}
}
# if HAVE_CFLOCALECOPYPREFERREDLANGUAGES /* MacOS X 10.5 or newer */
# if HAVE_CFLOCALECOPYPREFERREDLANGUAGES /* MacOS X 10.5 or newer */
CFRelease (prefArray);
# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.4 or newer */
# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.4 or newer */
}
# endif
# else
# endif
# else
const char *last_try =
get_main_locale_with_same_language (name);
if (last_try == NULL
|| setlocale_single (cat, last_try) == NULL)
warn = 1;
# endif
# endif
}
else
{
......@@ -1570,9 +1706,9 @@ rpl_setlocale (int category, const char *locale)
category_to_name (cat), name);
}
}
# else
# else
goto fail;
# endif
# endif
}
/* All steps were successful. */
......@@ -1597,7 +1733,7 @@ rpl_setlocale (int category, const char *locale)
}
else
{
# if defined _WIN32 && ! defined __CYGWIN__
# if defined _WIN32 && ! defined __CYGWIN__
if (category == LC_ALL && locale != NULL && strchr (locale, '.') != NULL)
{
char *saved_locale;
......@@ -1632,9 +1768,11 @@ rpl_setlocale (int category, const char *locale)
return setlocale (LC_ALL, NULL);
}
else
# endif
# endif
return setlocale_single (category, locale);
}
}
# endif /* NEED_SETLOCALE_IMPROVED */
#endif
# setlocale.m4 serial 6
# setlocale.m4 serial 7
dnl Copyright (C) 2011-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
......@@ -7,16 +7,20 @@ dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_SETLOCALE],
[
AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
AC_REQUIRE([AC_CANONICAL_HOST])
dnl Test whether we need to improve on the general working of setlocale.
NEED_SETLOCALE_IMPROVED=0
case "$host_os" in
dnl On native Windows systems, setlocale(category,NULL) does not look at
dnl the environment variables LC_ALL, category, and LANG.
mingw*) REPLACE_SETLOCALE=1 ;;
mingw*) NEED_SETLOCALE_IMPROVED=1 ;;
dnl On Cygwin 1.5.x, setlocale always succeeds but setlocale(LC_CTYPE,NULL)
dnl is then still "C".
cygwin*)
case `uname -r` in
1.5.*) REPLACE_SETLOCALE=1 ;;
1.5.*) NEED_SETLOCALE_IMPROVED=1 ;;
esac
;;
dnl On Android 4.3, setlocale(category,"C") always fails.
......@@ -42,10 +46,33 @@ int main ()
])
case "$gl_cv_func_setlocale_works" in
*yes) ;;
*) REPLACE_SETLOCALE=1 ;;
*) NEED_SETLOCALE_IMPROVED=1 ;;
esac
;;
esac
AC_DEFINE_UNQUOTED([NEED_SETLOCALE_IMPROVED], [$NEED_SETLOCALE_IMPROVED],
[Define to 1 to enable general improvements of setlocale.])
dnl Test whether we need a multithread-safe setlocale(category,NULL).
NEED_SETLOCALE_MTSAFE=0
if test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0; then
NEED_SETLOCALE_MTSAFE=1
fi
AC_DEFINE_UNQUOTED([NEED_SETLOCALE_MTSAFE], [$NEED_SETLOCALE_MTSAFE],
[Define to 1 to enable a multithread-safety fix of setlocale.])
if test $NEED_SETLOCALE_IMPROVED = 1 || test $NEED_SETLOCALE_MTSAFE = 1; then
REPLACE_SETLOCALE=1
fi
if test $NEED_SETLOCALE_MTSAFE = 1; then
LIB_SETLOCALE="$LIB_SETLOCALE_NULL"
else
LIB_SETLOCALE=
fi
dnl LIB_SETLOCALE is expected to be '-pthread' or '-lpthread' on AIX with gcc
dnl or xlc, and empty otherwise.
AC_SUBST([LIB_SETLOCALE])
])
# Prerequisites of lib/setlocale.c.
......
......@@ -9,3 +9,4 @@ configure.ac:
Makefile.am:
TESTS += test-astrxfrm
check_PROGRAMS += test-astrxfrm
test_astrxfrm_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -18,4 +18,4 @@ Makefile.am:
TESTS += test-btowc1.sh test-btowc2.sh
TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@'
check_PROGRAMS += test-btowc
test_btowc_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -11,3 +11,4 @@ configure.ac:
Makefile.am:
TESTS += test-c-ctype
check_PROGRAMS += test-c-ctype
test_c_ctype_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -13,5 +13,6 @@ gt_LOCALE_FR
Makefile.am:
TESTS += test-c-snprintf.sh
check_PROGRAMS += test-c-snprintf
TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@'
check_PROGRAMS += test-c-snprintf
test_c_snprintf_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -19,3 +19,5 @@ Makefile.am:
TESTS += test-c-strcase.sh
TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
check_PROGRAMS += test-c-strcasecmp test-c-strncasecmp
test_c_strcasecmp_LDADD = $(LDADD) $(LIB_SETLOCALE)
test_c_strncasecmp_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -13,5 +13,6 @@ gt_LOCALE_FR
Makefile.am:
TESTS += test-c-vasprintf.sh
check_PROGRAMS += test-c-vasprintf
TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@'
check_PROGRAMS += test-c-vasprintf
test_c_vasprintf_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -13,5 +13,6 @@ gt_LOCALE_FR
Makefile.am:
TESTS += test-c-vsnprintf.sh
check_PROGRAMS += test-c-vsnprintf
TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@'
check_PROGRAMS += test-c-vsnprintf
test_c_vsnprintf_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -14,6 +14,6 @@ gt_LOCALE_FR
Makefile.am:
TESTS += test-c-xvasprintf.sh
check_PROGRAMS += test-c-xvasprintf
test_c_xvasprintf_LDADD = $(LDADD) @LIBINTL@
TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@'
check_PROGRAMS += test-c-xvasprintf
test_c_xvasprintf_LDADD = $(LDADD) $(LIB_SETLOCALE) @LIBINTL@
......@@ -18,4 +18,4 @@ TESTS += \
dfa-match.sh
check_PROGRAMS += dfa-match-aux
dfa_match_aux_LDADD = $(LDADD) @LIBINTL@ $(LIBTHREAD)
dfa_match_aux_LDADD = $(LDADD) $(LIB_SETLOCALE) @LIBINTL@ $(LIBTHREAD)
......@@ -15,4 +15,4 @@ gt_FUNC_USELOCALE
Makefile.am:
TESTS += test-duplocale
check_PROGRAMS += test-duplocale
test_duplocale_LDADD = $(LDADD) @LIB_DUPLOCALE@
test_duplocale_LDADD = $(LDADD) $(LIB_SETLOCALE) @LIB_DUPLOCALE@
......@@ -16,4 +16,4 @@ Makefile.am:
TESTS += test-hard-locale
check_PROGRAMS += test-hard-locale
noinst_PROGRAMS += locale
test_hard_locale_LDADD = $(LDADD) @LIB_HARD_LOCALE@
test_hard_locale_LDADD = $(LDADD) $(LIB_SETLOCALE) @LIB_HARD_LOCALE@
......@@ -7,3 +7,4 @@ configure.ac:
Makefile.am:
noinst_PROGRAMS += test-localcharset
test_localcharset_LDADD = $(LDADD) $(LIB_SETLOCALE)
......@@ -15,5 +15,5 @@ AC_CHECK_FUNCS_ONCE([newlocale])
Makefile.am:
TESTS += test-localename
check_PROGRAMS += test-localename
test_localename_LDADD = $(LDADD) @INTL_MACOSX_LIBS@ $(LIBTHREAD)
test_localename_LDADD = $(LDADD) $(LIB_SETLOCALE) @INTL_MACOSX_LIBS@ $(LIBTHREAD)
......@@ -25,4 +25,4 @@ TESTS_ENVIRONMENT += \
LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
check_PROGRAMS += test-mbmemcasecmp
test_mbmemcasecmp_LDADD = $(LDADD) $(LIBTHREAD)
test_mbmemcasecmp_LDADD = $(LDADD) $(LIB_SETLOCALE) $(LIBTHREAD)
......@@ -25,4 +25,4 @@ TESTS_ENVIRONMENT += \
LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
check_PROGRAMS += test-mbmemcasecoll
test_mbmemcasecoll_LDADD = $(LDADD) $(LIBTHREAD)
test_mbmemcasecoll_LDADD = $(LDADD) $(LIB_SETLOCALE) $(LIBTHREAD)
......@@ -41,4 +41,4 @@ TESTS_ENVIRONMENT += \
LOCALE_JA='@LOCALE_JA@' \
LOCALE_ZH_CN='@LOCALE_ZH_CN@'
check_PROGRAMS += test-mbrtowc test-mbrtowc-w32
test_mbrtowc_LDADD = $(LDADD) $(LIBTHREAD)
test_mbrtowc_LDADD = $(LDADD) $(LIB_SETLOCALE) $(LIBTHREAD)