3 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_SETLOCALE],
10 AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
12 AC_REQUIRE([AC_CANONICAL_HOST])
14 dnl Test whether we need to improve on the general working of setlocale.
15 NEED_SETLOCALE_IMPROVED=0
17 dnl On native Windows systems, setlocale(category,NULL) does not look at
18 dnl the environment variables LC_ALL, category, and LANG.
19 mingw* | windows*) NEED_SETLOCALE_IMPROVED=1 ;;
20 dnl On Cygwin 1.5.x, setlocale always succeeds but setlocale(LC_CTYPE,NULL)
21 dnl is then still "C".
24 1.5.*) NEED_SETLOCALE_IMPROVED=1 ;;
27 dnl On Android 4.3, setlocale(category,"C") always fails.
29 AC_CACHE_CHECK([whether setlocale supports the C locale],
30 [gl_cv_func_setlocale_works],
36 return setlocale (LC_ALL, "C") == NULL;
38 [gl_cv_func_setlocale_works=yes],
39 [gl_cv_func_setlocale_works=no],
41 # Guess no on Android.
42 linux*-android*) gl_cv_func_setlocale_works="guessing no";;
43 # Guess yes otherwise.
44 *) gl_cv_func_setlocale_works="guessing yes";;
48 case "$gl_cv_func_setlocale_works" in
50 *) NEED_SETLOCALE_IMPROVED=1 ;;
54 AC_DEFINE_UNQUOTED([NEED_SETLOCALE_IMPROVED], [$NEED_SETLOCALE_IMPROVED],
55 [Define to 1 to enable general improvements of setlocale.])
57 dnl Test whether we need a multithread-safe setlocale(category,NULL).
58 NEED_SETLOCALE_MTSAFE=0
59 if test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0; then
60 NEED_SETLOCALE_MTSAFE=1
62 AC_DEFINE_UNQUOTED([NEED_SETLOCALE_MTSAFE], [$NEED_SETLOCALE_MTSAFE],
63 [Define to 1 to enable a multithread-safety fix of setlocale.])
65 if test $NEED_SETLOCALE_IMPROVED = 1 || test $NEED_SETLOCALE_MTSAFE = 1; then
69 if test $NEED_SETLOCALE_MTSAFE = 1; then
70 SETLOCALE_LIB="$SETLOCALE_NULL_LIB"
74 dnl SETLOCALE_LIB is expected to be '-pthread' or '-lpthread' on AIX with gcc
75 dnl or xlc, and empty otherwise.
76 AC_SUBST([SETLOCALE_LIB])
77 dnl For backward compatibility.
78 LIB_SETLOCALE="$SETLOCALE_LIB"
79 AC_SUBST([LIB_SETLOCALE])
82 # Prerequisites of lib/setlocale.c.
83 AC_DEFUN([gl_PREREQ_SETLOCALE],
85 dnl No need to check for CFLocaleCopyPreferredLanguages and
86 dnl CFPreferencesCopyAppValue because lib/setlocale.c is not used on Mac OS X.
87 dnl (The Mac OS X specific code is only used in libintl.)