Merge "Fix getpriority/setpriority types."
diff --git a/libc/Android.bp b/libc/Android.bp
index cea3305..094ad5c 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -54,6 +54,7 @@
 // ========================================================
 cc_defaults {
     name: "libc_defaults",
+    defaults: ["linux_bionic_supported"],
     cflags: libc_common_flags,
     asflags: libc_common_flags,
     conlyflags: ["-std=gnu99"],
@@ -1262,6 +1263,7 @@
         "bionic/ifaddrs.cpp",
         "bionic/inotify_init.cpp",
         "bionic/ioctl.cpp",
+        "bionic/langinfo.cpp",
         "bionic/lchown.cpp",
         "bionic/lfs64_support.cpp",
         "bionic/__libc_current_sigrtmax.cpp",
@@ -1623,6 +1625,7 @@
     static: {
         srcs: [
             "bionic/dl_iterate_phdr_static.cpp",
+            "bionic/icu_static.cpp",
             "bionic/malloc_common.cpp",
             "bionic/libc_init_static.cpp",
         ],
@@ -1633,6 +1636,7 @@
         srcs: [
             "arch-common/bionic/crtbegin_so.c",
             "arch-common/bionic/crtbrand.S",
+            "bionic/icu.cpp",
             "bionic/malloc_common.cpp",
             "bionic/libc_init_dynamic.cpp",
             "bionic/NetdClient.cpp",
@@ -1770,6 +1774,7 @@
 
 cc_defaults {
     name: "crt_defaults",
+    defaults: ["linux_bionic_supported"],
 
     no_default_compiler_flags: true,
 
diff --git a/libc/bionic/icu.cpp b/libc/bionic/icu.cpp
new file mode 100644
index 0000000..abc0eec
--- /dev/null
+++ b/libc/bionic/icu.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "private/icu.h"
+
+#include <dirent.h>
+#include <dlfcn.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+#include "private/libc_logging.h"
+
+// Allowed icu4c version numbers are in the range [44, 999].
+// Gingerbread's icu4c 4.4 is the minimum supported ICU version.
+static constexpr auto ICUDATA_VERSION_MIN_LENGTH = 2;
+static constexpr auto ICUDATA_VERSION_MAX_LENGTH = 3;
+static constexpr auto ICUDATA_VERSION_MIN = 44;
+
+static char g_icudata_version[ICUDATA_VERSION_MAX_LENGTH + 1];
+
+static void* g_libicuuc_handle = nullptr;
+
+static int __icu_dat_file_filter(const dirent* dirp) {
+  const char* name = dirp->d_name;
+
+  // Is the name the right length to match 'icudt(\d\d\d)l.dat'?
+  const size_t len = strlen(name);
+  if (len < 10 + ICUDATA_VERSION_MIN_LENGTH || len > 10 + ICUDATA_VERSION_MAX_LENGTH) return 0;
+
+  return !strncmp(name, "icudt", 5) && !strncmp(&name[len - 5], "l.dat", 5);
+}
+
+static bool __find_icu() {
+  dirent** namelist = nullptr;
+  int n = scandir("/system/usr/icu", &namelist, &__icu_dat_file_filter, alphasort);
+  int max_version = -1;
+  while (n--) {
+    // We prefer the latest version available.
+    int version = atoi(&namelist[n]->d_name[strlen("icudt")]);
+    if (version != 0 && version > max_version) max_version = version;
+    free(namelist[n]);
+  }
+  free(namelist);
+
+  if (max_version == -1 || max_version < ICUDATA_VERSION_MIN) {
+    __libc_write_log(ANDROID_LOG_ERROR, "bionic-icu", "couldn't find an ICU .dat file");
+    return false;
+  }
+
+  snprintf(g_icudata_version, sizeof(g_icudata_version), "_%d", max_version);
+
+  g_libicuuc_handle = dlopen("libicuuc.so", RTLD_LOCAL);
+  if (g_libicuuc_handle == nullptr) {
+    __libc_format_log(ANDROID_LOG_ERROR, "bionic-icu", "couldn't open libicuuc.so: %s", dlerror());
+    return false;
+  }
+
+  return true;
+}
+
+void* __find_icu_symbol(const char* symbol_name) {
+  static bool found_icu = __find_icu();
+  if (!found_icu) return nullptr;
+
+  char versioned_symbol_name[strlen(symbol_name) + sizeof(g_icudata_version)];
+  snprintf(versioned_symbol_name, sizeof(versioned_symbol_name), "%s%s",
+           symbol_name, g_icudata_version);
+
+  void* symbol = dlsym(g_libicuuc_handle, versioned_symbol_name);
+  if (symbol == nullptr) {
+    __libc_format_log(ANDROID_LOG_ERROR, "bionic-icu", "couldn't find %s", versioned_symbol_name);
+  }
+  return symbol;
+}
diff --git a/libc/bionic/icu_static.cpp b/libc/bionic/icu_static.cpp
new file mode 100644
index 0000000..cf24a38
--- /dev/null
+++ b/libc/bionic/icu_static.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "private/icu.h"
+
+// We don't have dlopen/dlsym for static binaries yet.
+void* __find_icu_symbol(const char*) {
+  return nullptr;
+}
diff --git a/libc/bionic/langinfo.cpp b/libc/bionic/langinfo.cpp
new file mode 100644
index 0000000..6f5057c
--- /dev/null
+++ b/libc/bionic/langinfo.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <langinfo.h>
+
+#include <stdlib.h>
+
+char* nl_langinfo(nl_item item) {
+  const char* result = "";
+  switch (item) {
+    case CODESET: result = (MB_CUR_MAX == 1) ? "ASCII" : "UTF-8"; break;
+
+    case D_T_FMT: result = "%F %T %z"; break;
+    case D_FMT: result = "%F"; break;
+    case T_FMT: result = "%T"; break;
+    case T_FMT_AMPM: result = "%I:%M:%S %p"; break;
+    case AM_STR: result = "AM"; break;
+    case PM_STR: result = "PM"; break;
+    case DAY_1: result = "Sunday"; break;
+    case DAY_2: result = "Monday"; break;
+    case DAY_3: result = "Tuesday"; break;
+    case DAY_4: result = "Wednesday"; break;
+    case DAY_5: result = "Thursday"; break;
+    case DAY_6: result = "Friday"; break;
+    case DAY_7: result = "Saturday"; break;
+    case ABDAY_1: result = "Sun"; break;
+    case ABDAY_2: result = "Mon"; break;
+    case ABDAY_3: result = "Tue"; break;
+    case ABDAY_4: result = "Wed"; break;
+    case ABDAY_5: result = "Thu"; break;
+    case ABDAY_6: result = "Fri"; break;
+    case ABDAY_7: result = "Sat"; break;
+    case MON_1: result = "January"; break;
+    case MON_2: result = "February"; break;
+    case MON_3: result = "March"; break;
+    case MON_4: result = "April"; break;
+    case MON_5: result = "May"; break;
+    case MON_6: result = "June"; break;
+    case MON_7: result = "July"; break;
+    case MON_8: result = "August"; break;
+    case MON_9: result = "September"; break;
+    case MON_10: result = "October"; break;
+    case MON_11: result = "November"; break;
+    case MON_12: result = "December"; break;
+    case ABMON_1: result = "Jan"; break;
+    case ABMON_2: result = "Feb"; break;
+    case ABMON_3: result = "Mar"; break;
+    case ABMON_4: result = "Apr"; break;
+    case ABMON_5: result = "May"; break;
+    case ABMON_6: result = "Jun"; break;
+    case ABMON_7: result = "Jul"; break;
+    case ABMON_8: result = "Aug"; break;
+    case ABMON_9: result = "Sep"; break;
+    case ABMON_10: result = "Oct"; break;
+    case ABMON_11: result = "Nov"; break;
+    case ABMON_12: result = "Dec"; break;
+    case ERA: result = ""; break;
+    case ERA_D_FMT: result = ""; break;
+    case ERA_D_T_FMT: result = ""; break;
+    case ERA_T_FMT: result = ""; break;
+    case ALT_DIGITS: result = ""; break;
+
+    case RADIXCHAR: result = "."; break;
+    case THOUSEP: result = ""; break;
+
+    case YESEXPR: result = "^[yY]"; break;
+    case NOEXPR: result = "^[nN]"; break;
+
+    case CRNCYSTR: result = ""; break;
+
+    default: break;
+  }
+  return const_cast<char*>(result);
+}
+
+char* nl_langinfo_l(nl_item item, locale_t) {
+  return nl_langinfo(item);
+}
diff --git a/libc/bionic/wctype.cpp b/libc/bionic/wctype.cpp
index cd8c39b..64c3467 100644
--- a/libc/bionic/wctype.cpp
+++ b/libc/bionic/wctype.cpp
@@ -34,26 +34,53 @@
 #include <string.h>
 #include <wchar.h>
 
-// These functions are either defined to be the same as their ASCII cousins,
-// or defined in terms of other functions.
-int iswalnum(wint_t wc) { return iswdigit(wc) || iswalpha(wc); }
-int iswblank(wint_t wc) { return isblank(wc); }
-int iswdigit(wint_t wc) { return isdigit(wc); }
-int iswgraph(wint_t wc) { return !iswspace(wc) && iswprint(wc); }
-int iswlower(wint_t wc) {
-  return towlower(wc) == wc && !(iswcntrl(wc) || iswdigit(wc) || iswpunct(wc) || iswspace(wc));
-}
-int iswupper(wint_t wc) {
-  return towupper(wc) == wc && !(iswcntrl(wc) || iswdigit(wc) || iswpunct(wc) || iswspace(wc));
-}
-int iswxdigit(wint_t wc) { return isxdigit(wc); }
+#include "private/icu.h"
 
-// TODO: need proper implementations of these.
-int iswalpha(wint_t wc) { return isalpha(wc); }
-int iswcntrl(wint_t wc) { return iscntrl(wc); }
-int iswprint(wint_t wc) { return isprint(wc); }
-int iswpunct(wint_t wc) { return ispunct(wc); }
-int iswspace(wint_t wc) { return isspace(wc); }
+static constexpr int UCHAR_ALPHABETIC = 0;
+static constexpr int UCHAR_LOWERCASE = 22;
+static constexpr int UCHAR_POSIX_ALNUM = 44;
+static constexpr int UCHAR_POSIX_BLANK = 45;
+static constexpr int UCHAR_POSIX_GRAPH = 46;
+static constexpr int UCHAR_POSIX_PRINT = 47;
+static constexpr int UCHAR_POSIX_XDIGIT = 48;
+static constexpr int UCHAR_UPPERCASE = 30;
+static constexpr int UCHAR_WHITE_SPACE = 31;
+
+static constexpr int U_CONTROL_CHAR = 15;
+
+static bool __icu_hasBinaryProperty(wint_t wc, int property, int (*fallback)(int)) {
+  typedef int (*FnT)(wint_t, int);
+  static auto u_hasBinaryProperty = reinterpret_cast<FnT>(__find_icu_symbol("u_hasBinaryProperty"));
+  return u_hasBinaryProperty ? u_hasBinaryProperty(wc, property) : fallback(wc);
+}
+
+int iswalnum(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_POSIX_ALNUM, isalnum); }
+int iswalpha(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_ALPHABETIC, isalpha); }
+int iswblank(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_POSIX_BLANK, isblank); }
+int iswgraph(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_POSIX_GRAPH, isgraph); }
+int iswlower(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_LOWERCASE, islower); }
+int iswprint(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_POSIX_PRINT, isprint); }
+int iswspace(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_WHITE_SPACE, isspace); }
+int iswupper(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_UPPERCASE, isupper); }
+int iswxdigit(wint_t wc) { return __icu_hasBinaryProperty(wc, UCHAR_POSIX_XDIGIT, isxdigit); }
+
+int iswcntrl(wint_t wc) {
+  typedef int (*FnT)(wint_t);
+  static auto u_charType = reinterpret_cast<FnT>(__find_icu_symbol("u_charType"));
+  return u_charType ? (u_charType(wc) == U_CONTROL_CHAR) : iscntrl(wc);
+}
+
+int iswdigit(wint_t wc) {
+  typedef int (*FnT)(wint_t);
+  static auto u_isdigit = reinterpret_cast<FnT>(__find_icu_symbol("u_isdigit"));
+  return u_isdigit ? u_isdigit(wc) : isdigit(wc);
+}
+
+int iswpunct(wint_t wc) {
+  typedef int (*FnT)(wint_t);
+  static auto u_ispunct = reinterpret_cast<FnT>(__find_icu_symbol("u_ispunct"));
+  return u_ispunct ? u_ispunct(wc) : ispunct(wc);
+}
 
 int iswalnum_l(wint_t c, locale_t) { return iswalnum(c); }
 int iswalpha_l(wint_t c, locale_t) { return iswalpha(c); }
@@ -90,12 +117,20 @@
   return iswctype(wc, char_class);
 }
 
-// TODO: need proper implementations of these.
-wint_t towlower(wint_t wc) { return tolower(wc); }
-wint_t towupper(wint_t wc) { return toupper(wc); }
+wint_t towlower(wint_t wc) {
+  typedef wchar_t (*FnT)(wchar_t);
+  static auto u_tolower = reinterpret_cast<FnT>(__find_icu_symbol("u_tolower"));
+  return u_tolower ? u_tolower(wc) : tolower(wc);
+}
 
-wint_t towupper_l(int c, locale_t) { return towupper(c); }
-wint_t towlower_l(int c, locale_t) { return towlower(c); }
+wint_t towupper(wint_t wc) {
+  typedef wchar_t (*FnT)(wchar_t);
+  static auto u_toupper = reinterpret_cast<FnT>(__find_icu_symbol("u_toupper"));
+  return u_toupper ? u_toupper(wc) : toupper(wc);
+}
+
+wint_t towupper_l(wint_t c, locale_t) { return towupper(c); }
+wint_t towlower_l(wint_t c, locale_t) { return towlower(c); }
 
 wctype_t wctype(const char* property) {
   static const char* const  properties[WC_TYPE_MAX] = {
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 13000f7..c6f0d24 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -134,8 +134,10 @@
 };
 #endif
 
+#if defined(__ANDROID__)
 // This should be synchronized to ResponseCode.h
 static const int DnsProxyQueryResult = 222;
+#endif
 
 static const struct afd {
 	int a_af;
@@ -399,6 +401,7 @@
   return true;
 }
 
+#if defined(__ANDROID__)
 // Returns 0 on success, else returns on error.
 static int
 android_getaddrinfo_proxy(
@@ -555,6 +558,7 @@
 	}
 	return EAI_NODATA;
 }
+#endif
 
 int
 getaddrinfo(const char *hostname, const char *servname,
diff --git a/libc/include/langinfo.h b/libc/include/langinfo.h
new file mode 100644
index 0000000..5c884ac
--- /dev/null
+++ b/libc/include/langinfo.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LANGINFO_H_
+#define _LANGINFO_H_
+
+#include <sys/cdefs.h>
+
+#include <nl_types.h>
+#include <xlocale.h>
+
+__BEGIN_DECLS
+
+#define CODESET 1
+#define D_T_FMT 2
+#define D_FMT 3
+#define T_FMT 4
+#define T_FMT_AMPM 5
+#define AM_STR 6
+#define PM_STR 7
+#define DAY_1 8
+#define DAY_2 9
+#define DAY_3 10
+#define DAY_4 11
+#define DAY_5 12
+#define DAY_6 13
+#define DAY_7 14
+#define ABDAY_1 15
+#define ABDAY_2 16
+#define ABDAY_3 17
+#define ABDAY_4 18
+#define ABDAY_5 19
+#define ABDAY_6 20
+#define ABDAY_7 21
+#define MON_1 22
+#define MON_2 23
+#define MON_3 24
+#define MON_4 25
+#define MON_5 26
+#define MON_6 27
+#define MON_7 28
+#define MON_8 29
+#define MON_9 30
+#define MON_10 31
+#define MON_11 32
+#define MON_12 33
+#define ABMON_1 34
+#define ABMON_2 35
+#define ABMON_3 36
+#define ABMON_4 37
+#define ABMON_5 38
+#define ABMON_6 39
+#define ABMON_7 40
+#define ABMON_8 41
+#define ABMON_9 42
+#define ABMON_10 43
+#define ABMON_11 44
+#define ABMON_12 45
+#define ERA 46
+#define ERA_D_FMT 47
+#define ERA_D_T_FMT 48
+#define ERA_T_FMT 49
+#define ALT_DIGITS 50
+#define RADIXCHAR 51
+#define THOUSEP 52
+#define YESEXPR 53
+#define NOEXPR 54
+#define CRNCYSTR 55
+
+char* nl_langinfo(nl_item) __INTRODUCED_IN_FUTURE;
+char* nl_langinfo_l(nl_item, locale_t) __INTRODUCED_IN_FUTURE;
+
+__END_DECLS
+
+#endif
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 1e239cd..cbdb438 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -148,7 +148,7 @@
 int lchown(const char* __path, uid_t __owner, gid_t __group);
 char* getcwd(char* __buf, size_t __size);
 
-int sync(void);
+void sync(void);
 
 int close(int __fd);
 
diff --git a/libc/include/wctype.h b/libc/include/wctype.h
index a0ed09a..9e22a8f 100644
--- a/libc/include/wctype.h
+++ b/libc/include/wctype.h
@@ -49,8 +49,8 @@
 int iswupper_l(wint_t, locale_t) __INTRODUCED_IN(21);
 int iswxdigit_l(wint_t, locale_t) __INTRODUCED_IN(21);
 
-wint_t towlower_l(int, locale_t) __INTRODUCED_IN(21);
-wint_t towupper_l(int, locale_t) __INTRODUCED_IN(21);
+wint_t towlower_l(wint_t, locale_t) __INTRODUCED_IN(21);
+wint_t towupper_l(wint_t, locale_t) __INTRODUCED_IN(21);
 #else
 // Implemented as static inlines before 21.
 #endif
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index eb75e8f..f9c5ede 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1288,6 +1288,8 @@
     msgget; # future
     msgrcv; # future
     msgsnd; # future
+    nl_langinfo; # future
+    nl_langinfo_l; # future
     pthread_getname_np; # future
     quotactl; # future
     semctl; # future
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 28755d4..179d8bf 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1210,6 +1210,8 @@
     msgget; # future
     msgrcv; # future
     msgsnd; # future
+    nl_langinfo; # future
+    nl_langinfo_l; # future
     pthread_getname_np; # future
     quotactl; # future
     semctl; # future
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 1fba8ee..f122937 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1313,6 +1313,8 @@
     msgget; # future
     msgrcv; # future
     msgsnd; # future
+    nl_langinfo; # future
+    nl_langinfo_l; # future
     pthread_getname_np; # future
     quotactl; # future
     semctl; # future
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index f61f615..a969703 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1272,6 +1272,8 @@
     msgget; # future
     msgrcv; # future
     msgsnd; # future
+    nl_langinfo; # future
+    nl_langinfo_l; # future
     pthread_getname_np; # future
     quotactl; # future
     semctl; # future
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 28755d4..179d8bf 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1210,6 +1210,8 @@
     msgget; # future
     msgrcv; # future
     msgsnd; # future
+    nl_langinfo; # future
+    nl_langinfo_l; # future
     pthread_getname_np; # future
     quotactl; # future
     semctl; # future
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index a166361..dfa839e 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1270,6 +1270,8 @@
     msgget; # future
     msgrcv; # future
     msgsnd; # future
+    nl_langinfo; # future
+    nl_langinfo_l; # future
     pthread_getname_np; # future
     quotactl; # future
     semctl; # future
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 28755d4..179d8bf 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1210,6 +1210,8 @@
     msgget; # future
     msgrcv; # future
     msgsnd; # future
+    nl_langinfo; # future
+    nl_langinfo_l; # future
     pthread_getname_np; # future
     quotactl; # future
     semctl; # future
diff --git a/libc/private/icu.h b/libc/private/icu.h
new file mode 100644
index 0000000..c5d89b8
--- /dev/null
+++ b/libc/private/icu.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _PRIVATE_ICU_H
+#define _PRIVATE_ICU_H
+
+void* __find_icu_symbol(const char* symbol_name);
+
+#endif  // _PRIVATE_ICU_H
diff --git a/libc/upstream-openbsd/lib/libc/include/langinfo.h b/libc/upstream-openbsd/lib/libc/include/langinfo.h
deleted file mode 100644
index a871ab8..0000000
--- a/libc/upstream-openbsd/lib/libc/include/langinfo.h
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Hack to build "vfprintf.c". */
-#define RADIXCHAR 1
-#define nl_langinfo(i) ((i == RADIXCHAR) ? (char*) "." : NULL)
diff --git a/libdl/Android.bp b/libdl/Android.bp
index 273a887..9db3a94 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -2,6 +2,9 @@
 // libdl
 //
 cc_library {
+    name: "libdl",
+
+    defaults: ["linux_bionic_supported"],
 
     // NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from
     // libgcc.a are made static to libdl.so.  This in turn ensures that libraries that
@@ -46,8 +49,6 @@
     ],
     stl: "none",
 
-    name: "libdl",
-
     // NOTE: libdl needs __aeabi_unwind_cpp_pr0 from libgcc.a but libgcc.a needs a
     // few symbols from libc. Using --no-undefined here results in having to link
     // against libc creating a circular dependency which is removed and we end up
diff --git a/libm/Android.bp b/libm/Android.bp
index 11017f6..35f5fe4 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -5,6 +5,7 @@
 //
 cc_library {
     name: "libm",
+    defaults: ["linux_bionic_supported"],
 
     srcs: [
         "upstream-freebsd/lib/msun/bsdsrc/b_exp.c",
diff --git a/linker/Android.bp b/linker/Android.bp
index 4d770ac..5745d73 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -1,6 +1,7 @@
 cc_library_static {
     name: "liblinker_malloc",
     clang: true,
+    defaults: ["linux_bionic_supported"],
 
     srcs: [
         "linker_allocator.cpp",
@@ -13,6 +14,7 @@
 
 cc_binary {
     clang: true,
+    defaults: ["linux_bionic_supported"],
 
     srcs: [
         "dlfcn.cpp",
@@ -112,7 +114,6 @@
         "libbase",
         "libz",
         "liblog",
-        "libdebuggerd_client",
 
         // Important: The liblinker_malloc should be the last library in the list
         // to overwrite any other malloc implementations by other static libraries.
@@ -131,9 +132,15 @@
        },
     },
     target: {
+        android: {
+            static_libs: ["libdebuggerd_client"],
+        },
         android64: {
             cflags: ["-DTARGET_IS_64_BIT"],
         },
+        linux_bionic: {
+            cflags: ["-DTARGET_IS_64_BIT"],
+        },
     },
     compile_multilib: "both",
 
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index 2e98bf0..a8cc814 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -40,7 +40,9 @@
 
 #include "android-base/strings.h"
 #include "android-base/stringprintf.h"
+#ifdef __ANDROID__
 #include "debuggerd/client.h"
+#endif
 
 #include <vector>
 
@@ -217,6 +219,7 @@
   __system_properties_init(); // may use 'environ'
 
   // Register the debuggerd signal handler.
+#ifdef __ANDROID__
   debuggerd_callbacks_t callbacks = {
     .get_abort_message = []() {
       return g_abort_message;
@@ -224,6 +227,7 @@
     .post_dump = &notify_gdb_of_libraries,
   };
   debuggerd_init(&callbacks);
+#endif
 
   g_linker_logger.ResetState();
 
diff --git a/tests/Android.bp b/tests/Android.bp
index 688d8e1..a9d302a 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -68,6 +68,7 @@
         "grp_pwd_test.cpp",
         "ifaddrs_test.cpp",
         "inttypes_test.cpp",
+        "langinfo_test.cpp",
         "libc_logging_test.cpp",
         "libgen_basename_test.cpp",
         "libgen_test.cpp",
@@ -385,6 +386,12 @@
     name: "bionic-unit-tests",
     defaults: ["bionic_unit_tests_defaults", "bionic_tests_defaults"],
     clang: true,
+
+    target: {
+        android: {
+            shared_libs: ["libicuuc"],
+        },
+    },
 }
 
 cc_test {
diff --git a/tests/langinfo_test.cpp b/tests/langinfo_test.cpp
new file mode 100644
index 0000000..6eae8bc
--- /dev/null
+++ b/tests/langinfo_test.cpp
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include <langinfo.h>
+
+TEST(langinfo, category_CTYPE) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  EXPECT_STREQ("UTF-8", nl_langinfo(CODESET));
+}
+
+TEST(langinfo, category_TIME) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+#if defined(__BIONIC__)
+  // bionic's C locale is ISO rather than en_US.
+  EXPECT_STREQ("%F %T %z", nl_langinfo(D_T_FMT));
+  EXPECT_STREQ("%F", nl_langinfo(D_FMT));
+#else
+  EXPECT_STREQ("%a %d %b %Y %r %Z", nl_langinfo(D_T_FMT));
+  EXPECT_STREQ("%m/%d/%Y", nl_langinfo(D_FMT));
+#endif
+  EXPECT_STREQ("%T", nl_langinfo(T_FMT));
+  EXPECT_STREQ("%I:%M:%S %p", nl_langinfo(T_FMT_AMPM));
+  EXPECT_STREQ("AM", nl_langinfo(AM_STR));
+  EXPECT_STREQ("PM", nl_langinfo(PM_STR));
+  EXPECT_STREQ("Sunday", nl_langinfo(DAY_1));
+  EXPECT_STREQ("Monday", nl_langinfo(DAY_2));
+  EXPECT_STREQ("Tuesday", nl_langinfo(DAY_3));
+  EXPECT_STREQ("Wednesday", nl_langinfo(DAY_4));
+  EXPECT_STREQ("Thursday", nl_langinfo(DAY_5));
+  EXPECT_STREQ("Friday", nl_langinfo(DAY_6));
+  EXPECT_STREQ("Saturday", nl_langinfo(DAY_7));
+  EXPECT_STREQ("Sun", nl_langinfo(ABDAY_1));
+  EXPECT_STREQ("Mon", nl_langinfo(ABDAY_2));
+  EXPECT_STREQ("Tue", nl_langinfo(ABDAY_3));
+  EXPECT_STREQ("Wed", nl_langinfo(ABDAY_4));
+  EXPECT_STREQ("Thu", nl_langinfo(ABDAY_5));
+  EXPECT_STREQ("Fri", nl_langinfo(ABDAY_6));
+  EXPECT_STREQ("Sat", nl_langinfo(ABDAY_7));
+  EXPECT_STREQ("January", nl_langinfo(MON_1));
+  EXPECT_STREQ("February", nl_langinfo(MON_2));
+  EXPECT_STREQ("March", nl_langinfo(MON_3));
+  EXPECT_STREQ("April", nl_langinfo(MON_4));
+  EXPECT_STREQ("May", nl_langinfo(MON_5));
+  EXPECT_STREQ("June", nl_langinfo(MON_6));
+  EXPECT_STREQ("July", nl_langinfo(MON_7));
+  EXPECT_STREQ("August", nl_langinfo(MON_8));
+  EXPECT_STREQ("September", nl_langinfo(MON_9));
+  EXPECT_STREQ("October", nl_langinfo(MON_10));
+  EXPECT_STREQ("November", nl_langinfo(MON_11));
+  EXPECT_STREQ("December", nl_langinfo(MON_12));
+  EXPECT_STREQ("Jan", nl_langinfo(ABMON_1));
+  EXPECT_STREQ("Feb", nl_langinfo(ABMON_2));
+  EXPECT_STREQ("Mar", nl_langinfo(ABMON_3));
+  EXPECT_STREQ("Apr", nl_langinfo(ABMON_4));
+  EXPECT_STREQ("May", nl_langinfo(ABMON_5));
+  EXPECT_STREQ("Jun", nl_langinfo(ABMON_6));
+  EXPECT_STREQ("Jul", nl_langinfo(ABMON_7));
+  EXPECT_STREQ("Aug", nl_langinfo(ABMON_8));
+  EXPECT_STREQ("Sep", nl_langinfo(ABMON_9));
+  EXPECT_STREQ("Oct", nl_langinfo(ABMON_10));
+  EXPECT_STREQ("Nov", nl_langinfo(ABMON_11));
+  EXPECT_STREQ("Dec", nl_langinfo(ABMON_12));
+  EXPECT_STREQ("", nl_langinfo(ERA));
+  EXPECT_STREQ("", nl_langinfo(ERA_D_FMT));
+  EXPECT_STREQ("", nl_langinfo(ERA_D_T_FMT));
+  EXPECT_STREQ("", nl_langinfo(ERA_T_FMT));
+  EXPECT_STREQ("", nl_langinfo(ALT_DIGITS));
+}
+
+TEST(langinfo, category_NUMERIC) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  EXPECT_STREQ(".", nl_langinfo(RADIXCHAR));
+  EXPECT_STREQ("", nl_langinfo(THOUSEP));
+}
+
+TEST(langinfo, category_MESSAGES) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  EXPECT_STREQ("^[yY]", nl_langinfo(YESEXPR));
+  EXPECT_STREQ("^[nN]", nl_langinfo(NOEXPR));
+}
+
+TEST(langinfo, category_MONETARY) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  // POSIX says that if the currency symbol is the empty string (as it is for
+  // the C locale), an implementation can return the empty string and not
+  // include the leading [+-.] that signifies where the currency symbol should
+  // appear. For consistency with localeconv (which POSIX says to prefer for
+  // RADIXCHAR, THOUSEP, and CRNCYSTR) we return the empty string. glibc
+  // disagrees.
+#if defined(__BIONIC__)
+  EXPECT_STREQ("", nl_langinfo(CRNCYSTR));
+#else
+  EXPECT_STREQ("-", nl_langinfo(CRNCYSTR));
+#endif
+}
+
+TEST(langinfo, invalid) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  EXPECT_STREQ("", nl_langinfo(-1));
+  EXPECT_STREQ("", nl_langinfo(0));
+  EXPECT_STREQ("", nl_langinfo(666));
+}
+
+TEST(langinfo, matches_localeconv) {
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  EXPECT_STREQ(localeconv()->decimal_point, nl_langinfo(RADIXCHAR));
+  EXPECT_STREQ(localeconv()->thousands_sep, nl_langinfo(THOUSEP));
+#if defined(__BIONIC__)
+  // (See comment in category_MONETARY test.)
+  EXPECT_STREQ(localeconv()->currency_symbol, nl_langinfo(CRNCYSTR));
+#endif
+}
diff --git a/tests/wctype_test.cpp b/tests/wctype_test.cpp
index fe2e374..84a0e65 100644
--- a/tests/wctype_test.cpp
+++ b/tests/wctype_test.cpp
@@ -16,6 +16,8 @@
 
 #include <wctype.h>
 
+#include <dlfcn.h>
+
 #include <gtest/gtest.h>
 
 class UtfLocale {
@@ -25,63 +27,75 @@
   locale_t l;
 };
 
+// bionic's dlsym doesn't work in static binaries, so we can't access icu,
+// so any unicode test case will fail.
+static bool have_dl = (dlopen("libc.so", 0) != nullptr);
+
 static void TestIsWideFn(int fn(wint_t),
                          int fn_l(wint_t, locale_t),
                          const wchar_t* trues,
                          const wchar_t* falses) {
   UtfLocale l;
   for (const wchar_t* p = trues; *p; ++p) {
+    if (!have_dl && *p > 0x7f) {
+      GTEST_LOG_(INFO) << "skipping unicode test " << *p;
+      continue;
+    }
     EXPECT_TRUE(fn(*p)) << *p;
     EXPECT_TRUE(fn_l(*p, l.l)) << *p;
   }
   for (const wchar_t* p = falses; *p; ++p) {
+    if (!have_dl && *p > 0x7f) {
+      GTEST_LOG_(INFO) << "skipping unicode test " << *p;
+      continue;
+    }
     EXPECT_FALSE(fn(*p)) << *p;
     EXPECT_FALSE(fn_l(*p, l.l)) << *p;
   }
 }
 
 TEST(wctype, iswalnum) {
-  TestIsWideFn(iswalnum, iswalnum_l, L"1aA", L"! \b");
+  TestIsWideFn(iswalnum, iswalnum_l, L"1aAÇçΔδ", L"! \b");
 }
 
 TEST(wctype, iswalpha) {
-  TestIsWideFn(iswalpha, iswalpha_l, L"aA", L"1! \b");
+  TestIsWideFn(iswalpha, iswalpha_l, L"aAÇçΔδ", L"1! \b");
 }
 
 TEST(wctype, iswblank) {
-  TestIsWideFn(iswblank, iswblank_l, L" \t", L"1aA!\b");
+  TestIsWideFn(iswblank, iswblank_l, L" \t", L"1aA!\bÇçΔδ");
 }
 
 TEST(wctype, iswcntrl) {
-  TestIsWideFn(iswcntrl, iswcntrl_l, L"\b", L"1aA! ");
+  TestIsWideFn(iswcntrl, iswcntrl_l, L"\b\u009f", L"1aA! ÇçΔδ");
 }
 
 TEST(wctype, iswdigit) {
-  TestIsWideFn(iswdigit, iswdigit_l, L"1", L"aA! \b");
+  TestIsWideFn(iswdigit, iswdigit_l, L"1", L"aA! \bÇçΔδ");
 }
 
 TEST(wctype, iswgraph) {
-  TestIsWideFn(iswgraph, iswgraph_l, L"1aA!", L" \b");
+  TestIsWideFn(iswgraph, iswgraph_l, L"1aA!ÇçΔδ", L" \b");
 }
 
 TEST(wctype, iswlower) {
-  TestIsWideFn(iswlower, iswlower_l, L"a", L"1A! \b");
+  TestIsWideFn(iswlower, iswlower_l, L"açδ", L"1A! \bÇΔ");
 }
 
 TEST(wctype, iswprint) {
-  TestIsWideFn(iswprint, iswprint_l, L"1aA! ", L"\b");
+  TestIsWideFn(iswprint, iswprint_l, L"1aA! ÇçΔδ", L"\b");
 }
 
 TEST(wctype, iswpunct) {
-  TestIsWideFn(iswpunct, iswpunct_l, L"!", L"1aA \b");
+  TestIsWideFn(iswpunct, iswpunct_l, L"!", L"1aA \bÇçΔδ");
 }
 
 TEST(wctype, iswspace) {
-  TestIsWideFn(iswspace, iswspace_l, L" \f\t", L"1aA!\b");
+  TestIsWideFn(iswspace, iswspace_l, L" \f\t", L"1aA!\bÇçΔδ");
 }
 
 TEST(wctype, iswupper) {
-  TestIsWideFn(iswupper, iswupper_l, L"A", L"1a! \b");
+  TestIsWideFn(iswupper, iswupper_l, L"AÇΔ", L"1a! \bçδ");
 }
 
 TEST(wctype, iswxdigit) {
@@ -89,29 +103,65 @@
 }
 
 TEST(wctype, towlower) {
+  EXPECT_EQ(WEOF, towlower(WEOF));
   EXPECT_EQ(wint_t('!'), towlower(L'!'));
   EXPECT_EQ(wint_t('a'), towlower(L'a'));
   EXPECT_EQ(wint_t('a'), towlower(L'A'));
+  if (have_dl) {
+    EXPECT_EQ(wint_t(L'ç'), towlower(L'ç'));
+    EXPECT_EQ(wint_t(L'ç'), towlower(L'Ç'));
+    EXPECT_EQ(wint_t(L'δ'), towlower(L'δ'));
+    EXPECT_EQ(wint_t(L'δ'), towlower(L'Δ'));
+  } else {
+    GTEST_LOG_(INFO) << "skipping unicode towlower tests";
+  }
 }
 
 TEST(wctype, towlower_l) {
   UtfLocale l;
+  EXPECT_EQ(WEOF, towlower(WEOF));
   EXPECT_EQ(wint_t('!'), towlower_l(L'!', l.l));
   EXPECT_EQ(wint_t('a'), towlower_l(L'a', l.l));
   EXPECT_EQ(wint_t('a'), towlower_l(L'A', l.l));
+  if (have_dl) {
+    EXPECT_EQ(wint_t(L'ç'), towlower_l(L'ç', l.l));
+    EXPECT_EQ(wint_t(L'ç'), towlower_l(L'Ç', l.l));
+    EXPECT_EQ(wint_t(L'δ'), towlower_l(L'δ', l.l));
+    EXPECT_EQ(wint_t(L'δ'), towlower_l(L'Δ', l.l));
+  } else {
+    GTEST_LOG_(INFO) << "skipping unicode towlower_l tests";
+  }
 }
 
 TEST(wctype, towupper) {
+  EXPECT_EQ(WEOF, towupper(WEOF));
   EXPECT_EQ(wint_t('!'), towupper(L'!'));
   EXPECT_EQ(wint_t('A'), towupper(L'a'));
   EXPECT_EQ(wint_t('A'), towupper(L'A'));
+  if (have_dl) {
+    EXPECT_EQ(wint_t(L'Ç'), towupper(L'ç'));
+    EXPECT_EQ(wint_t(L'Ç'), towupper(L'Ç'));
+    EXPECT_EQ(wint_t(L'Δ'), towupper(L'δ'));
+    EXPECT_EQ(wint_t(L'Δ'), towupper(L'Δ'));
+  } else {
+    GTEST_LOG_(INFO) << "skipping unicode towupper tests";
+  }
 }
 
 TEST(wctype, towupper_l) {
   UtfLocale l;
+  EXPECT_EQ(WEOF, towupper_l(WEOF, l.l));
   EXPECT_EQ(wint_t('!'), towupper_l(L'!', l.l));
   EXPECT_EQ(wint_t('A'), towupper_l(L'a', l.l));
   EXPECT_EQ(wint_t('A'), towupper_l(L'A', l.l));
+  if (have_dl) {
+    EXPECT_EQ(wint_t(L'Ç'), towupper_l(L'ç', l.l));
+    EXPECT_EQ(wint_t(L'Ç'), towupper_l(L'Ç', l.l));
+    EXPECT_EQ(wint_t(L'Δ'), towupper_l(L'δ', l.l));
+    EXPECT_EQ(wint_t(L'Δ'), towupper_l(L'Δ', l.l));
+  } else {
+    GTEST_LOG_(INFO) << "skipping unicode towupper_l tests";
+  }
 }
 
 TEST(wctype, wctype) {