Home | History | Annotate | Download | only in include
      1 /*
      2   Copyright (C) 2005-2012 Rich Felker
      3 
      4   Permission is hereby granted, free of charge, to any person obtaining
      5   a copy of this software and associated documentation files (the
      6   "Software"), to deal in the Software without restriction, including
      7   without limitation the rights to use, copy, modify, merge, publish,
      8   distribute, sublicense, and/or sell copies of the Software, and to
      9   permit persons to whom the Software is furnished to do so, subject to
     10   the following conditions:
     11 
     12   The above copyright notice and this permission notice shall be
     13   included in all copies or substantial portions of the Software.
     14 
     15   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     16   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     17   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     18   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
     19   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     20   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     21   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     22 
     23   Modified in 2013 for the Android Open Source Project.
     24  */
     25 #ifndef NDK_ANDROID_SUPPORT_WCHAR_H
     26 #define NDK_ANDROID_SUPPORT_WCHAR_H
     27 
     28 // __LP64__
     29 
     30 /* IMPORTANT NOTE: Unlike other headers in the support library, this
     31  * one doesn't try to include the Bionic header through #include_next.
     32  *
     33  * This is intentional, and comes from the fact that before Gingerbread,
     34  * i.e. API level 9, the platform didn't really support wide chars, more
     35  * precisely:
     36  *    - wchar_t is defined as an 8-bit unsigned integer.
     37  *    - the few wchar-related functions available are just stubs
     38  *      to their 8-bit counterparts (e.g. wcslen() -> strlen()).
     39  *
     40  * Starting from API level 9, wchar_t is a 32-bit unsigned integer,
     41  * and wchar-related functions implement support for it with several
     42  * gotchas:
     43  *    - no proper Unicode support (e.g. towlower() only works on ASCII
     44  *      codepoints, ignores all others).
     45  *
     46  *    - no wprintf() and wscanf() functionality.
     47  *
     48  *    - no multi-byte conversion routines.
     49  *
     50  * By completely overriding the C library functions, the support library
     51  * can be used to generate code that will run properly on _any_ version
     52  * of Android.
     53  *
     54  * This implementation supports the following:
     55  *
     56  *    - Unicode code points in wchar_t, and working towlower() / towupper()
     57  *      using the en_US.UTF-8 case mappings.
     58  *
     59  *    - Multi-byte encoding/decoding to/from UTF-8 (no other multibyte
     60  *      encoding are supported).
     61  *
     62  *    - wprintf() / wfprintf() support.
     63  *
     64  *    - wscanf() / wfscanf() coming soon :)
     65  */
     66 #ifdef __cplusplus
     67 extern "C" {
     68 #endif
     69 
     70 #if defined(__LP64__)
     71 
     72 # include_next <wchar.h>
     73 #include <xlocale.h> // for locale_t
     74 
     75 #else
     76 
     77 #include <stdarg.h>  // for va_list
     78 #include <stdio.h>   // for FILE
     79 #include <stddef.h>  // for size_t
     80 #include <wctype.h>
     81 #include <xlocale.h> // for locale_t
     82 
     83 #define __need___wchar_t
     84 #include <stddef.h>
     85 
     86 #ifndef WCHAR_MAX
     87 #define WCHAR_MAX __WCHAR_MAX__
     88 /* Clang does not define __WCHAR_MIN__ */
     89 #if defined(__WCHAR_UNSIGNED__)
     90 #define WCHAR_MIN L'\0'
     91 #else
     92 #define WCHAR_MIN (-(WCHAR_MAX) - 1)
     93 #endif
     94 #endif
     95 
     96 #define WEOF ((wint_t)(-1))
     97 
     98 typedef struct
     99 {
    100   unsigned __opaque1, __opaque2;
    101 } mbstate_t;
    102 
    103 wchar_t *wcscpy (wchar_t *__restrict__, const wchar_t *__restrict__);
    104 wchar_t *wcsncpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
    105 
    106 wchar_t *wcscat (wchar_t *__restrict__, const wchar_t *__restrict__);
    107 wchar_t *wcsncat (wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
    108 
    109 int wcscmp (const wchar_t *, const wchar_t *);
    110 int wcsncmp (const wchar_t *, const wchar_t *, size_t);
    111 
    112 int wcscoll(const wchar_t *, const wchar_t *);
    113 size_t wcsxfrm (wchar_t *__restrict__, const wchar_t *__restrict__, size_t n);
    114 
    115 wchar_t *wcschr (const wchar_t *, wchar_t);
    116 wchar_t *wcsrchr (const wchar_t *, wchar_t);
    117 
    118 size_t wcscspn (const wchar_t *, const wchar_t *);
    119 size_t wcsspn (const wchar_t *, const wchar_t *);
    120 wchar_t *wcspbrk (const wchar_t *, const wchar_t *);
    121 
    122 wchar_t *wcstok (wchar_t *__restrict__, const wchar_t *__restrict__, wchar_t **__restrict__);
    123 
    124 size_t wcslen (const wchar_t *);
    125 
    126 wchar_t *wcsstr (const wchar_t *__restrict__, const wchar_t *__restrict__);
    127 wchar_t *wcswcs (const wchar_t *, const wchar_t *);
    128 
    129 wchar_t *wmemchr (const wchar_t *, wchar_t, size_t);
    130 int wmemcmp (const wchar_t *, const wchar_t *, size_t);
    131 wchar_t *wmemcpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
    132 wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t);
    133 wchar_t *wmemset (wchar_t *, wchar_t, size_t);
    134 
    135 wint_t btowc (int);
    136 int wctob (wint_t);
    137 
    138 int mbsinit (const mbstate_t *);
    139 size_t mbrtowc (wchar_t *__restrict__, const char *__restrict__, size_t, mbstate_t *__restrict__);
    140 size_t wcrtomb (char *__restrict__, wchar_t, mbstate_t *__restrict__);
    141 
    142 size_t mbrlen (const char *__restrict__, size_t, mbstate_t *__restrict__);
    143 
    144 size_t mbsrtowcs (wchar_t *__restrict__, const char **__restrict__, size_t, mbstate_t *__restrict__);
    145 size_t wcsrtombs (char *__restrict__, const wchar_t **__restrict__, size_t, mbstate_t *__restrict__);
    146 
    147 float wcstof (const wchar_t *__restrict__, wchar_t **__restrict__);
    148 double wcstod (const wchar_t *__restrict__, wchar_t **__restrict__);
    149 long double wcstold (const wchar_t *__restrict__, wchar_t **__restrict__);
    150 
    151 long wcstol (const wchar_t *__restrict__, wchar_t **__restrict__, int);
    152 unsigned long wcstoul (const wchar_t *__restrict__, wchar_t **__restrict__, int);
    153 
    154 long long wcstoll (const wchar_t *__restrict__, wchar_t **__restrict__, int);
    155 unsigned long long wcstoull (const wchar_t *__restrict__, wchar_t **__restrict__, int);
    156 intmax_t wcstoimax (const wchar_t * nptr, wchar_t** endptr , int base);
    157 uintmax_t wcstoumax (const wchar_t * nptr, wchar_t** endptr , int base);
    158 
    159 
    160 int fwide (FILE *, int);
    161 
    162 
    163 int wprintf (const wchar_t *__restrict__, ...);
    164 int fwprintf (FILE *__restrict__, const wchar_t *__restrict__, ...);
    165 int swprintf (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, ...);
    166 
    167 int vwprintf (const wchar_t *__restrict__, va_list);
    168 int vfwprintf (FILE *__restrict__, const wchar_t *__restrict__, va_list);
    169 int vswprintf (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, va_list);
    170 
    171 int wscanf (const wchar_t *__restrict__, ...);
    172 int fwscanf (FILE *__restrict__, const wchar_t *__restrict__, ...);
    173 int swscanf (const wchar_t *__restrict__, const wchar_t *__restrict__, ...);
    174 
    175 int vwscanf (const wchar_t *__restrict__, va_list);
    176 int vfwscanf (FILE *__restrict__, const wchar_t *__restrict__, va_list);
    177 int vswscanf (const wchar_t *__restrict__, const wchar_t *__restrict__, va_list);
    178 
    179 wint_t fgetwc (FILE *);
    180 wint_t getwc (FILE *);
    181 wint_t getwchar (void);
    182 
    183 wint_t fputwc (wchar_t, FILE *);
    184 wint_t putwc (wchar_t, FILE *);
    185 wint_t putwchar (wchar_t);
    186 
    187 wchar_t *fgetws (wchar_t *__restrict__, int, FILE *__restrict__);
    188 int fputws (const wchar_t *__restrict__, FILE *__restrict__);
    189 
    190 wint_t ungetwc (wint_t, FILE *);
    191 
    192 struct tm;
    193 size_t wcsftime (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, const struct tm *__restrict__);
    194 
    195 FILE *open_wmemstream(wchar_t **, size_t *);
    196 size_t mbsnrtowcs(wchar_t *__restrict__, const char **__restrict__, size_t, size_t, mbstate_t *__restrict__);
    197 size_t wcsnrtombs(char *__restrict__, const wchar_t **__restrict__, size_t, size_t, mbstate_t *__restrict__);
    198 wchar_t *wcsdup(const wchar_t *);
    199 size_t wcsnlen (const wchar_t *, size_t);
    200 wchar_t *wcpcpy (wchar_t *__restrict__, const wchar_t *__restrict__);
    201 wchar_t *wcpncpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
    202 int wcscasecmp(const wchar_t *, const wchar_t *);
    203 int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t);
    204 int wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
    205 int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t);
    206 int wcwidth (wchar_t);
    207 int wcswidth (const wchar_t *, size_t);
    208 int       iswalnum(wint_t);
    209 int       iswalpha(wint_t);
    210 int       iswblank(wint_t);
    211 int       iswcntrl(wint_t);
    212 int       iswdigit(wint_t);
    213 int       iswgraph(wint_t);
    214 int       iswlower(wint_t);
    215 int       iswprint(wint_t);
    216 int       iswpunct(wint_t);
    217 int       iswspace(wint_t);
    218 int       iswupper(wint_t);
    219 int       iswxdigit(wint_t);
    220 int       iswctype(wint_t, wctype_t);
    221 wint_t    towlower(wint_t);
    222 wint_t    towupper(wint_t);
    223 wctype_t  wctype(const char *);
    224 
    225 #endif // !__LP64__
    226 
    227 int wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
    228 size_t wcsxfrm_l(wchar_t *__restrict__, const wchar_t *__restrict__, size_t n, locale_t);
    229 
    230 #ifdef __cplusplus
    231 }  // extern "C"
    232 #endif
    233 
    234 #endif  // NDK_ANDROID_SUPPORT_WCHAR_H
    235