[PATCH] Add Android support.
Dan Albert
danalbert at google.com
Wed Jun 25 16:31:08 PDT 2014
---
include/__config | 2 +
include/__locale | 6 ++-
include/locale | 8 ++--
include/support/android/locale_bionic.h | 68 +++++++++++++++++++++++++++++++++
src/locale.cpp | 4 +-
5 files changed, 82 insertions(+), 6 deletions(-)
create mode 100644 include/support/android/locale_bionic.h
diff --git a/include/__config b/include/__config
index c628524..004fbf0 100644
--- a/include/__config
+++ b/include/__config
@@ -317,6 +317,8 @@ typedef __char32_t char32_t;
#if defined(__FreeBSD__)
#define _LIBCPP_HAS_QUICK_EXIT
#define _LIBCPP_HAS_C11_FEATURES
+#elif defined(__ANDROID__)
+#define _LIBCPP_HAS_QUICK_EXIT
#elif defined(__linux__)
#include <features.h>
#if __GLIBC_PREREQ(2, 15)
diff --git a/include/__locale b/include/__locale
index fb5b196..57a4cfe 100644
--- a/include/__locale
+++ b/include/__locale
@@ -23,6 +23,8 @@
# include <support/win32/locale_win32.h>
#elif defined(_AIX)
# include <support/ibm/xlocale.h>
+#elif defined(__ANDROID__)
+# include <support/android/locale_bionic.h>
#elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)
# include <xlocale.h>
#endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
@@ -341,13 +343,15 @@ public:
static const mask punct = _PUNCT;
static const mask xdigit = _HEX;
static const mask blank = _BLANK;
-#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__ANDROID__)
#ifdef __APPLE__
typedef __uint32_t mask;
#elif defined(__FreeBSD__)
typedef unsigned long mask;
#elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
typedef unsigned short mask;
+#elif defined(__ANDROID__)
+ typedef char mask;
#endif
static const mask space = _CTYPE_S;
static const mask print = _CTYPE_R;
diff --git a/include/locale b/include/locale
index 7191290..a52f3e0 100644
--- a/include/locale
+++ b/include/locale
@@ -193,7 +193,7 @@ template <class charT> class messages_byname;
#include <ctime>
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
#include <support/win32/locale_win32.h>
-#else // _LIBCPP_MSVCRT
+#elif !defined(__ANDROID__)
#include <nl_types.h>
#endif // !_LIBCPP_MSVCRT
@@ -3673,7 +3673,7 @@ template <class _CharT>
typename messages<_CharT>::catalog
messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
{
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__ANDROID__)
return -1;
#else // _WIN32
catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
@@ -3688,7 +3688,7 @@ typename messages<_CharT>::string_type
messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
const string_type& __dflt) const
{
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__ANDROID__)
return __dflt;
#else // _WIN32
string __ndflt;
@@ -3710,7 +3710,7 @@ template <class _CharT>
void
messages<_CharT>::do_close(catalog __c) const
{
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__ANDROID__)
if (__c != -1)
__c <<= 1;
nl_catd __cat = (nl_catd)__c;
diff --git a/include/support/android/locale_bionic.h b/include/support/android/locale_bionic.h
new file mode 100644
index 0000000..fa15b16
--- /dev/null
+++ b/include/support/android/locale_bionic.h
@@ -0,0 +1,68 @@
+// -*- C++ -*-
+//===------------------- support/android/locale_bionic.h ------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H
+#define _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H
+
+#if defined(__ANDROID__)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <xlocale.h>
+
+#define isalnum_l(c, locale) isalnum(c)
+#define isalpha_l(c, locale) isalpha(c)
+#define isascii_l(c, locale) isascii(c)
+#define isblank_l(c, locale) isblank(c)
+#define iscntrl_l(c, locale) iscntrl(c)
+#define isdigit_l(c, locale) isdigit(c)
+#define isgraph_l(c, locale) isgraph(c)
+#define islower_l(c, locale) islower(c)
+#define isprint_l(c, locale) isprint(c)
+#define ispunct_l(c, locale) ispunct(c)
+#define isspace_l(c, locale) isspace(c)
+#define isupper_l(c, locale) isupper(c)
+#define isxdigit_l(c, locale) isxdigit(c)
+#define iswalnum_l(c, locale) iswalnum(c)
+#define iswalpha_l(c, locale) iswalpha(c)
+#define iswascii_l(c, locale) iswascii(c)
+#define iswblank_l(c, locale) iswblank(c)
+#define iswcntrl_l(c, locale) iswcntrl(c)
+#define iswdigit_l(c, locale) iswdigit(c)
+#define iswgraph_l(c, locale) iswgraph(c)
+#define iswlower_l(c, locale) iswlower(c)
+#define iswprint_l(c, locale) iswprint(c)
+#define iswpunct_l(c, locale) iswpunct(c)
+#define iswspace_l(c, locale) iswspace(c)
+#define iswupper_l(c, locale) iswupper(c)
+#define iswxdigit_l(c, locale) iswxdigit(c)
+#define toupper_l(c, locale) toupper(c)
+#define tolower_l(c, locale) tolower(c)
+#define towupper_l(c, locale) towupper(c)
+#define towlower_l(c, locale) towlower(c)
+#define strcoll_l(s1, s2, locale) strcoll(s1, s2)
+#define strxfrm_l(dest, src, n, locale) strxfrm(dest, src, n)
+#define strftime_l(s, max, format, tm, locale) strftime(s, max, format, tm)
+#define wcscoll_l(s1, s2, locale) wcscoll(s1, s2)
+#define wcsxfrm_l(dest, src, n, locale) wcsxfrm(dest, src, n)
+#define strtold_l(nptr, endptr, locale) strtold(nptr, endptr)
+#define strtoll_l(nptr, endptr, base, locale) strtoll(nptr, endptr, base)
+#define strtoull_l(nptr, endptr, base, locale) strtoull(nptr, endptr, base)
+#define wcstoll_l(nptr, endptr, locale) wcstoll(nptr, endptr)
+#define wcstoull_l(nptr, endptr, locale) wcstoull(nptr, endptr)
+#define wcstold_l(nptr, endptr, locale) wcstold(nptr, endptr)
+
+#ifdef __cplusplus
+}
+#endif
+#endif // defined(__ANDROID__)
+#endif // _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H
diff --git a/src/locale.cpp b/src/locale.cpp
index 4877f2b..76c43e8 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -30,7 +30,7 @@
#include "__sso_allocator"
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
#include <support/win32/locale_win32.h>
-#else // _LIBCPP_MSVCRT
+#elif !defined(__ANDROID__)
#include <langinfo.h>
#endif // !_LIBCPP_MSVCRT
#include <stdlib.h>
@@ -1037,6 +1037,8 @@ ctype<char>::classic_table() _NOEXCEPT
return *__ctype_b_loc();
#elif defined(_AIX)
return (const unsigned int *)__lc_ctype_ptr->obj->mask;
+#elif defined(__ANDROID__)
+ return _ctype_;
#else
// Platform not supported: abort so the person doing the port knows what to
// fix
--
2.0.0.526.g5318336
More information about the cfe-commits
mailing list