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 /* IMPORTANT NOTE: Unlike other headers in the support library, this 29 * one doesn't try to include the Bionic header through #include_next. 30 * 31 * This is intentional, and comes from the fact that before Gingerbread, 32 * i.e. API level 9, the platform didn't really support wide chars, more 33 * precisely: 34 * - wchar_t is defined as an 8-bit unsigned integer. 35 * - the few wchar-related functions available are just stubs 36 * to their 8-bit counterparts (e.g. wcslen() -> strlen()). 37 * 38 * Starting from API level 9, wchar_t is a 32-bit unsigned integer, 39 * and wchar-related functions implement support for it with several 40 * gotchas: 41 * - no proper Unicode support (e.g. towlower() only works on ASCII 42 * codepoints, ignores all others). 43 * 44 * - no wprintf() and wscanf() functionality. 45 * 46 * - no multi-byte conversion routines. 47 * 48 * By completely overriding the C library functions, the support library 49 * can be used to generate code that will run properly on _any_ version 50 * of Android. 51 * 52 * This implementation supports the following: 53 * 54 * - Unicode code points in wchar_t, and working towlower() / towupper() 55 * using the en_US.UTF-8 case mappings. 56 * 57 * - Multi-byte encoding/decoding to/from UTF-8 (no other multibyte 58 * encoding are supported). 59 * 60 * - wprintf() / wfprintf() support. 61 * 62 * - wscanf() / wfscanf() coming soon :) 63 */ 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 #include <stdarg.h> // for va_list 69 #include <stdio.h> // for FILE 70 #include <stddef.h> // for size_t 71 #include <wctype.h> 72 73 typedef int wint_t; 74 75 #define __need___wchar_t 76 #include <stddef.h> 77 78 typedef int wctype_t; 79 typedef struct locale_struct* locale_t; 80 81 // See http://b.android.com/This is tricky: <stdio.h> indirectly includes <stdint.h>, which will 82 // already have defined WCHAR_MIN / WCHAR_MAX in the following cases: 83 // - When compiling C sources 84 // - When compiling C++ sources AND having __STDC_LIMIT_MACROS defined. 85 // 86 // The conditional block below is only entered when compiling 87 // C++ sources without __STDC_LIMIT_MACROS. 88 // 89 // The constants here ensure that they match the INT32_MIN / INT32_MAX 90 // definitions. 91 #ifndef WCHAR_MAX 92 # ifndef __WCHAR_MAX__ 93 # error "__WCHAR_MAX__ undefined. Check your toolchain." 94 # endif 95 // Clang doesn't define __WCHAR_MIN__, only __WCHAR_MAX__ 96 # ifndef __WCHAR_MIN__ 97 # if __WCHAR_MAX__ == 0xffffffff 98 # define __WCHAR_MIN__ 0U 99 # elif __WCHAR_MAX__ == 0x7fffffff 100 # define __WCHAR_MIN__ 0x80000000 101 # else 102 # error "Invalid __WCHAR_MAX__ value. Check your toolchain." 103 # endif 104 # endif // !__WCHAR_MIN 105 #define WCHAR_MAX __WCHAR_MAX__ 106 #define WCHAR_MIN __WCHAR_MIN__ 107 #endif 108 109 #define WEOF ((wint_t)(-1)) 110 111 typedef struct 112 { 113 unsigned __opaque1, __opaque2; 114 } mbstate_t; 115 116 wchar_t *wcscpy (wchar_t *__restrict__, const wchar_t *__restrict__); 117 wchar_t *wcsncpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 118 119 wchar_t *wcscat (wchar_t *__restrict__, const wchar_t *__restrict__); 120 wchar_t *wcsncat (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 121 122 int wcscmp (const wchar_t *, const wchar_t *); 123 int wcsncmp (const wchar_t *, const wchar_t *, size_t); 124 125 int wcscoll(const wchar_t *, const wchar_t *); 126 size_t wcsxfrm (wchar_t *__restrict__, const wchar_t *__restrict__, size_t n); 127 128 wchar_t *wcschr (const wchar_t *, wchar_t); 129 wchar_t *wcsrchr (const wchar_t *, wchar_t); 130 131 size_t wcscspn (const wchar_t *, const wchar_t *); 132 size_t wcsspn (const wchar_t *, const wchar_t *); 133 wchar_t *wcspbrk (const wchar_t *, const wchar_t *); 134 135 wchar_t *wcstok (wchar_t *__restrict__, const wchar_t *__restrict__, wchar_t **__restrict__); 136 137 size_t wcslen (const wchar_t *); 138 139 wchar_t *wcsstr (const wchar_t *__restrict__, const wchar_t *__restrict__); 140 wchar_t *wcswcs (const wchar_t *, const wchar_t *); 141 142 wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); 143 int wmemcmp (const wchar_t *, const wchar_t *, size_t); 144 wchar_t *wmemcpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 145 wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); 146 wchar_t *wmemset (wchar_t *, wchar_t, size_t); 147 148 wint_t btowc (int); 149 int wctob (wint_t); 150 151 int mbsinit (const mbstate_t *); 152 size_t mbrtowc (wchar_t *__restrict__, const char *__restrict__, size_t, mbstate_t *__restrict__); 153 size_t wcrtomb (char *__restrict__, wchar_t, mbstate_t *__restrict__); 154 155 size_t mbrlen (const char *__restrict__, size_t, mbstate_t *__restrict__); 156 157 size_t mbsrtowcs (wchar_t *__restrict__, const char **__restrict__, size_t, mbstate_t *__restrict__); 158 size_t wcsrtombs (char *__restrict__, const wchar_t **__restrict__, size_t, mbstate_t *__restrict__); 159 160 float wcstof (const wchar_t *__restrict__, wchar_t **__restrict__); 161 double wcstod (const wchar_t *__restrict__, wchar_t **__restrict__); 162 long double wcstold (const wchar_t *__restrict__, wchar_t **__restrict__); 163 164 long wcstol (const wchar_t *__restrict__, wchar_t **__restrict__, int); 165 unsigned long wcstoul (const wchar_t *__restrict__, wchar_t **__restrict__, int); 166 167 long long wcstoll (const wchar_t *__restrict__, wchar_t **__restrict__, int); 168 unsigned long long wcstoull (const wchar_t *__restrict__, wchar_t **__restrict__, int); 169 170 171 172 int fwide (FILE *, int); 173 174 175 int wprintf (const wchar_t *__restrict__, ...); 176 int fwprintf (FILE *__restrict__, const wchar_t *__restrict__, ...); 177 int swprintf (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, ...); 178 179 int vwprintf (const wchar_t *__restrict__, va_list); 180 int vfwprintf (FILE *__restrict__, const wchar_t *__restrict__, va_list); 181 int vswprintf (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, va_list); 182 183 int wscanf (const wchar_t *__restrict__, ...); 184 int fwscanf (FILE *__restrict__, const wchar_t *__restrict__, ...); 185 int swscanf (const wchar_t *__restrict__, const wchar_t *__restrict__, ...); 186 187 int vwscanf (const wchar_t *__restrict__, va_list); 188 int vfwscanf (FILE *__restrict__, const wchar_t *__restrict__, va_list); 189 int vswscanf (const wchar_t *__restrict__, const wchar_t *__restrict__, va_list); 190 191 wint_t fgetwc (FILE *); 192 wint_t getwc (FILE *); 193 wint_t getwchar (void); 194 195 wint_t fputwc (wchar_t, FILE *); 196 wint_t putwc (wchar_t, FILE *); 197 wint_t putwchar (wchar_t); 198 199 wchar_t *fgetws (wchar_t *__restrict__, int, FILE *__restrict__); 200 int fputws (const wchar_t *__restrict__, FILE *__restrict__); 201 202 wint_t ungetwc (wint_t, FILE *); 203 204 struct tm; 205 size_t wcsftime (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, const struct tm *__restrict__); 206 207 FILE *open_wmemstream(wchar_t **, size_t *); 208 size_t mbsnrtowcs(wchar_t *__restrict__, const char **__restrict__, size_t, size_t, mbstate_t *__restrict__); 209 size_t wcsnrtombs(char *__restrict__, const wchar_t **__restrict__, size_t, size_t, mbstate_t *__restrict__); 210 wchar_t *wcsdup(const wchar_t *); 211 size_t wcsnlen (const wchar_t *, size_t); 212 wchar_t *wcpcpy (wchar_t *__restrict__, const wchar_t *__restrict__); 213 wchar_t *wcpncpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 214 int wcscasecmp(const wchar_t *, const wchar_t *); 215 int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); 216 int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); 217 int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); 218 int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); 219 size_t wcsxfrm_l(wchar_t *__restrict__, const wchar_t *__restrict__, size_t n, locale_t); 220 221 int wcwidth (wchar_t); 222 int wcswidth (const wchar_t *, size_t); 223 int iswalnum(wint_t); 224 int iswalpha(wint_t); 225 int iswblank(wint_t); 226 int iswcntrl(wint_t); 227 int iswdigit(wint_t); 228 int iswgraph(wint_t); 229 int iswlower(wint_t); 230 int iswprint(wint_t); 231 int iswpunct(wint_t); 232 int iswspace(wint_t); 233 int iswupper(wint_t); 234 int iswxdigit(wint_t); 235 int iswctype(wint_t, wctype_t); 236 wint_t towlower(wint_t); 237 wint_t towupper(wint_t); 238 wctype_t wctype(const char *); 239 240 #ifdef __cplusplus 241 } // extern "C" 242 #endif 243 244 #endif // NDK_ANDROID_SUPPORT_WCHAR_H 245