]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
intl: Work around setlocale bug on Android 4.3.
authorBruno Haible <bruno@clisp.org>
Sun, 19 May 2019 22:25:51 +0000 (00:25 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Apr 2020 10:50:20 +0000 (12:50 +0200)
* gettext-runtime/intl/setlocale.c (setlocale_unixlike): New wrapper for
Android.

gettext-runtime/intl/setlocale.c

index 52071220f5719f5488824bbe6614d89ebfaff87d..2995db1c83ce4023b48b3b15735919fa8834a50f 100644 (file)
@@ -1,5 +1,5 @@
 /* setlocale() function that respects the locale chosen by the user.
-   Copyright (C) 2009, 2011, 2013, 2018 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2011, 2013, 2018-2019 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2009.
 
    This program is free software: you can redistribute it and/or modify
@@ -802,6 +802,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