Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle newlocale

  • Loading branch information...
commit a0ace63e170f549bea9e9bbec473698402717e9e 1 parent 97cb8c2
Shinichiro Hamaji authored
Showing with 41 additions and 0 deletions.
  1. +39 −0 libmac/mac.c
  2. +2 −0  rename.tab
View
39 libmac/mac.c
@@ -31,6 +31,7 @@
#include <dirent.h>
#include <err.h>
+#include <locale.h>
#include <pthread.h>
#include <signal.h>
#include <spawn.h>
@@ -1255,6 +1256,44 @@ unsigned int arc4random() {
return rand();
}
+#define __DARWIN_LC_ALL_MASK ( __DARWIN_LC_COLLATE_MASK \
+ | __DARWIN_LC_CTYPE_MASK \
+ | __DARWIN_LC_MESSAGES_MASK \
+ | __DARWIN_LC_MONETARY_MASK \
+ | __DARWIN_LC_NUMERIC_MASK \
+ | __DARWIN_LC_TIME_MASK )
+#define __DARWIN_LC_COLLATE_MASK (1 << 0)
+#define __DARWIN_LC_CTYPE_MASK (1 << 1)
+#define __DARWIN_LC_MESSAGES_MASK (1 << 2)
+#define __DARWIN_LC_MONETARY_MASK (1 << 3)
+#define __DARWIN_LC_NUMERIC_MASK (1 << 4)
+#define __DARWIN_LC_TIME_MASK (1 << 5)
+
+locale_t __darwin_newlocale(int category_mask, const char* locale,
+ locale_t base) {
+ LOGF("newlocale: %d %p %p\n", category_mask, locale, base);
+ int linux_category_mask = 0;
+ if (__DARWIN_LC_COLLATE_MASK & category_mask)
+ linux_category_mask |= LC_COLLATE_MASK;
+ if (__DARWIN_LC_CTYPE_MASK & category_mask)
+ linux_category_mask |= LC_CTYPE_MASK;
+ if (__DARWIN_LC_MESSAGES_MASK & category_mask)
+ linux_category_mask |= LC_MESSAGES_MASK;
+ if (__DARWIN_LC_MONETARY_MASK & category_mask)
+ linux_category_mask |= LC_MONETARY_MASK;
+ if (__DARWIN_LC_NUMERIC_MASK & category_mask)
+ linux_category_mask |= LC_NUMERIC_MASK;
+ if (__DARWIN_LC_TIME_MASK & category_mask)
+ linux_category_mask |= LC_TIME_MASK;
+ // Apple's newlocale allows base=LC_GLOBAL_LOCALE, while glibc crashes.
+ // It seems the behavior is unspecified for this case.
+ // http://pubs.opengroup.org/onlinepubs/9699919799/functions/newlocale.html
+ // We'll use current locale (NULL) instead of the global locale.
+ if (base == LC_GLOBAL_LOCALE)
+ base = NULL;
+ return newlocale(linux_category_mask, locale, base);
+}
+
__attribute__((constructor)) void initMac() {
__darwin_stdin = __init_darwin_FILE(stdin);
__darwin_stdout = __init_darwin_FILE(stdout);
View
2  rename.tab
@@ -149,3 +149,5 @@ WRAP(uname)
RENAME(select$1050, select)
WRAP(qsort_r)
+
+WRAP(newlocale)
Please sign in to comment.
Something went wrong with that request. Please try again.