Add support for BIONIC C library (Android). Patch from Dan Albert

Change-Id: I9ead4d8a1d16e71d57fdc7696457cfcc3de4f713
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@212724 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2014-07-10 15:20:28 +00:00
committed by Dan Albert
parent 3bfb9441d6
commit e45cf3e8b5
5 changed files with 184 additions and 59 deletions

View File

@@ -317,9 +317,9 @@ typedef __char32_t char32_t;
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
#define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_QUICK_EXIT
#define _LIBCPP_HAS_C11_FEATURES #define _LIBCPP_HAS_C11_FEATURES
#elif defined(__BIONIC__) #elif defined(__ANDROID__)
#define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_QUICK_EXIT
#elif defined(__linux__) && defined(__GLIBC__) #elif defined(__linux__)
#include <features.h> #include <features.h>
#if __GLIBC_PREREQ(2, 15) #if __GLIBC_PREREQ(2, 15)
#define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_QUICK_EXIT

View File

@@ -24,10 +24,15 @@
#elif defined(_AIX) #elif defined(_AIX)
# include <support/ibm/xlocale.h> # include <support/ibm/xlocale.h>
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
# include <support/android/locale_bionic.h> // Android gained the locale aware functions in L (API level 21)
#elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(__EMSCRIPTEN__) || defined(__IBMCPP__) # include <android/api-level.h>
# if __ANDROID_API__ <= 20
# include <support/android/locale_bionic.h>
# endif
#elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) \
|| defined(__sun__) || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
# include <xlocale.h> # include <xlocale.h>
#endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__ #endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header #pragma GCC system_header

View File

@@ -193,11 +193,9 @@ template <class charT> class messages_byname;
#include <ctime> #include <ctime>
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
#include <support/win32/locale_win32.h> #include <support/win32/locale_win32.h>
#elif defined(__ANDROID__) #elif !defined(__ANDROID__)
#include <support/android/nl_types.h>
#else // _LIBCPP_MSVCRT
#include <nl_types.h> #include <nl_types.h>
#endif // !_LIBCPP_MSVCRT #endif
#ifdef __APPLE__ #ifdef __APPLE__
#include <Availability.h> #include <Availability.h>
@@ -3675,14 +3673,14 @@ template <class _CharT>
typename messages<_CharT>::catalog typename messages<_CharT>::catalog
messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
{ {
#ifdef _WIN32 #if defined(_WIN32) || defined(__ANDROID__)
return -1; return -1;
#else // _WIN32 #else // _WIN32 || __ANDROID__
catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
if (__cat != -1) if (__cat != -1)
__cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1)); __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
return __cat; return __cat;
#endif // _WIN32 #endif // _WIN32 || __ANDROID__
} }
template <class _CharT> template <class _CharT>
@@ -3690,7 +3688,7 @@ typename messages<_CharT>::string_type
messages<_CharT>::do_get(catalog __c, int __set, int __msgid, messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
const string_type& __dflt) const const string_type& __dflt) const
{ {
#ifdef _WIN32 #if defined(_WIN32) || defined(__ANDROID__)
return __dflt; return __dflt;
#else // _WIN32 #else // _WIN32
string __ndflt; string __ndflt;
@@ -3712,7 +3710,7 @@ template <class _CharT>
void void
messages<_CharT>::do_close(catalog __c) const messages<_CharT>::do_close(catalog __c) const
{ {
#if !defined(_WIN32) #if !defined(_WIN32) && !defined(__ANDROID__)
if (__c != -1) if (__c != -1)
__c <<= 1; __c <<= 1;
nl_catd __cat = (nl_catd)__c; nl_catd __cat = (nl_catd)__c;

View File

@@ -17,49 +17,173 @@
extern "C" { extern "C" {
#endif #endif
#include <stdlib.h>
#include <xlocale.h> #include <xlocale.h>
#define isalnum_l(c, locale) isalnum(c) static inline int isalnum_l(int c, locale_t) {
#define isalpha_l(c, locale) isalpha(c) return isalnum(c);
#define isascii_l(c, locale) isascii(c) }
#define isblank_l(c, locale) isblank(c)
#define iscntrl_l(c, locale) iscntrl(c) static inline int isalpha_l(int c, locale_t) {
#define isdigit_l(c, locale) isdigit(c) return isalpha(c);
#define isgraph_l(c, locale) isgraph(c) }
#define islower_l(c, locale) islower(c)
#define isprint_l(c, locale) isprint(c) static inline int isblank_l(int c, locale_t) {
#define ispunct_l(c, locale) ispunct(c) return isblank(c);
#define isspace_l(c, locale) isspace(c) }
#define isupper_l(c, locale) isupper(c)
#define isxdigit_l(c, locale) isxdigit(c) static inline int iscntrl_l(int c, locale_t) {
#define iswalnum_l(c, locale) iswalnum(c) return iscntrl(c);
#define iswalpha_l(c, locale) iswalpha(c) }
#define iswascii_l(c, locale) iswascii(c)
#define iswblank_l(c, locale) iswblank(c) static inline int isdigit_l(int c, locale_t) {
#define iswcntrl_l(c, locale) iswcntrl(c) return isdigit(c);
#define iswdigit_l(c, locale) iswdigit(c) }
#define iswgraph_l(c, locale) iswgraph(c)
#define iswlower_l(c, locale) iswlower(c) static inline int isgraph_l(int c, locale_t) {
#define iswprint_l(c, locale) iswprint(c) return isgraph(c);
#define iswpunct_l(c, locale) iswpunct(c) }
#define iswspace_l(c, locale) iswspace(c)
#define iswupper_l(c, locale) iswupper(c) static inline int islower_l(int c, locale_t) {
#define iswxdigit_l(c, locale) iswxdigit(c) return islower(c);
#define toupper_l(c, locale) toupper(c) }
#define tolower_l(c, locale) tolower(c)
#define towupper_l(c, locale) towupper(c) static inline int isprint_l(int c, locale_t) {
#define towlower_l(c, locale) towlower(c) return isprint(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) static inline int ispunct_l(int c, locale_t) {
#define wcscoll_l(s1, s2, locale) wcscoll(s1, s2) return ispunct(c);
#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) static inline int isspace_l(int c, locale_t) {
#define strtoull_l(nptr, endptr, base, locale) strtoull(nptr, endptr, base) return isspace(c);
#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) static inline int isupper_l(int c, locale_t) {
return isupper(c);
}
static inline int isxdigit_l(int c, locale_t) {
return isxdigit(c);
}
static inline int iswalnum_l(wint_t c, locale_t) {
return iswalnum(c);
}
static inline int iswalpha_l(wint_t c, locale_t) {
return iswalpha(c);
}
static inline int iswblank_l(wint_t c, locale_t) {
return iswblank(c);
}
static inline int iswcntrl_l(wint_t c, locale_t) {
return iswcntrl(c);
}
static inline int iswdigit_l(wint_t c, locale_t) {
return iswdigit(c);
}
static inline int iswgraph_l(wint_t c, locale_t) {
return iswgraph(c);
}
static inline int iswlower_l(wint_t c, locale_t) {
return iswlower(c);
}
static inline int iswprint_l(wint_t c, locale_t) {
return iswprint(c);
}
static inline int iswpunct_l(wint_t c, locale_t) {
return iswpunct(c);
}
static inline int iswspace_l(wint_t c, locale_t) {
return iswspace(c);
}
static inline int iswupper_l(wint_t c, locale_t) {
return iswupper(c);
}
static inline int iswxdigit_l(wint_t c, locale_t) {
return iswxdigit(c);
}
static inline int toupper_l(int c, locale_t) {
return toupper(c);
}
static inline int tolower_l(int c, locale_t) {
return tolower(c);
}
static inline int towupper_l(int c, locale_t) {
return towupper(c);
}
static inline int towlower_l(int c, locale_t) {
return towlower(c);
}
static inline int strcoll_l(const char *s1, const char *s2, locale_t) {
return strcoll(s1, s2);
}
static inline size_t strxfrm_l(char *dest, const char *src, size_t n,
locale_t) {
return strxfrm(dest, src, n);
}
static inline size_t strftime_l(char *s, size_t max, const char *format,
const struct tm *tm, locale_t) {
return strftime(s, max, format, tm);
}
static inline int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t) {
return wcscoll(ws1, ws2);
}
static inline size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t n,
locale_t) {
return wcsxfrm(dest, src, n);
}
static inline long double strtold_l(const char *nptr, char **endptr, locale_t) {
return strtold(nptr, endptr);
}
static inline long long strtoll_l(const char *nptr, char **endptr, size_t base,
locale_t) {
return strtoll(nptr, endptr, base);
}
static inline unsigned long long strtoull_l(const char *nptr, char **endptr,
size_t base, locale_t) {
return strtoull(nptr, endptr, base);
}
static inline long long wcstoll_l(const wchar_t *nptr, wchar_t **endptr,
size_t base, locale_t) {
return wcstoll(nptr, endptr, base);
}
static inline unsigned long long wcstoull_l(const wchar_t *nptr,
wchar_t **endptr, size_t base,
locale_t) {
return wcstoull(nptr, endptr, base);
}
static inline long double wcstold_l(const wchar_t *nptr, wchar_t **endptr,
locale_t) {
return wcstold(nptr, endptr);
}
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -30,11 +30,9 @@
#include "__sso_allocator" #include "__sso_allocator"
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
#include <support/win32/locale_win32.h> #include <support/win32/locale_win32.h>
#elif defined(__ANDROID__) #elif !defined(__ANDROID__)
#include <support/android/langinfo.h>
#else // _LIBCPP_MSVCRT
#include <langinfo.h> #include <langinfo.h>
#endif // !_LIBCPP_MSVCRT #endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>