]> Savannah Git Hosting - gnulib.git/commitdiff
setlocale: Work around bug on Android 4.3.
authorBruno Haible <bruno@clisp.org>
Fri, 25 Jan 2019 22:26:24 +0000 (23:26 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 25 Jan 2019 22:26:24 +0000 (23:26 +0100)
* m4/setlocale.m4 (gl_FUNC_SETLOCALE): Test whether setlocale supports
the "C" locale.
* lib/setlocale.c (setlocale_unixlike): New wrapper for Android.
* doc/posix-functions/setlocale.texi: Mention the Android bug.

ChangeLog
doc/posix-functions/setlocale.texi
lib/setlocale.c
m4/setlocale.m4

index ab3ac61cec52a775c51e85a541cd7badfbbd0856..a47fb01e43015a9136c5522791271b9a0f986d3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-01-25  Bruno Haible  <bruno@clisp.org>
+
+       setlocale: Work around bug on Android 4.3.
+       * m4/setlocale.m4 (gl_FUNC_SETLOCALE): Test whether setlocale supports
+       the "C" locale.
+       * lib/setlocale.c (setlocale_unixlike): New wrapper for Android.
+       * doc/posix-functions/setlocale.texi: Mention the Android bug.
+
 2019-01-24  Bruno Haible  <bruno@clisp.org>
 
        memchr: Work around bug on Android <= 5.0.
index 1da6d13396246df8d54e7132bc54811e63f0cfaf..32c9902b326e347fe591b71eda92255ff447f865 100644 (file)
@@ -20,6 +20,10 @@ On Windows platforms (excluding Cygwin) and Cygwin 1.5.x,
 On Windows platforms (excluding Cygwin), @code{setlocale} understands different
 locale names, that are not based on ISO 639 language names and ISO 3166 country
 names.
+@item
+On Android 4.3, which which doesn't have locales, the @code{setlocale} function
+always fails.  The replacement, however, supports only the locale names
+@code{"C"} and @code{"POSIX"}.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 3abdf2cd78bb6a96681afc5f808ee7a4c301795f..e14805ec001a8876c730468cfa57ad56d43f6871 100644 (file)
@@ -794,6 +794,39 @@ setlocale_unixlike (int category, const char *locale)
   return NULL;
 }
 
+# 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);
+  if (result == NULL)
+    switch (category)
+      {
+      case LC_CTYPE:
+      case LC_NUMERIC:
+      case LC_TIME:
+      case LC_COLLATE:
+      case LC_MONETARY:
+      case LC_MESSAGES:
+      case LC_ALL:
+      case LC_PAPER:
+      case LC_NAME:
+      case LC_ADDRESS:
+      case LC_TELEPHONE:
+      case LC_MEASUREMENT:
+        if (locale == NULL
+            || strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0)
+          result = (char *) "C";
+        break;
+      default:
+        break;
+      }
+  return result;
+}
+#  define setlocale setlocale_unixlike
+
 # else
 #  define setlocale_unixlike setlocale
 # endif
index d04985cd1a2c5bad262dd7df6640702a600df677..dba68c4e4ffcf30fb0252b1db315bec967be56fd 100644 (file)
@@ -1,4 +1,4 @@
-# setlocale.m4 serial 5
+# setlocale.m4 serial 6
 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,
@@ -19,6 +19,32 @@ AC_DEFUN([gl_FUNC_SETLOCALE],
         1.5.*) REPLACE_SETLOCALE=1 ;;
       esac
       ;;
+    dnl On Android 4.3, setlocale(category,"C") always fails.
+    *)
+      AC_CACHE_CHECK([whether setlocale supports the C locale],
+        [gl_cv_func_setlocale_works],
+        [AC_RUN_IFELSE(
+           [AC_LANG_SOURCE([[
+#include <locale.h>
+int main ()
+{
+  return setlocale (LC_ALL, "C") == NULL;
+}]])],
+           [gl_cv_func_setlocale_works=yes],
+           [gl_cv_func_setlocale_works=no],
+           [case "$host_os" in
+                               # Guess no on Android.
+              linux*-android*) gl_cv_func_setlocale_works="guessing no";;
+                               # Guess yes otherwise.
+              *)               gl_cv_func_setlocale_works="guessing yes";;
+            esac
+           ])
+        ])
+      case "$gl_cv_func_setlocale_works" in
+        *yes) ;;
+        *) REPLACE_SETLOCALE=1 ;;
+      esac
+      ;;
   esac
 ])