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 #if defined(__LP64__) 65 66 #include_next <wchar.h> 67 68 #else 69 70 #ifdef __cplusplus 71 extern "C" { 72 #endif 73 74 #include <stdarg.h> // for va_list 75 #include <stdio.h> // for FILE 76 #include <stddef.h> // for size_t 77 #include <wctype.h> 78 #include <xlocale.h> // for locale_t 79 80 #define __need___wchar_t 81 #include <stddef.h> 82 83 #ifndef WCHAR_MAX 84 #define WCHAR_MAX __WCHAR_MAX__ 85 /* Clang does not define __WCHAR_MIN__ */ 86 #if defined(__WCHAR_UNSIGNED__) 87 #define WCHAR_MIN L'\0' 88 #else 89 #define WCHAR_MIN (-(WCHAR_MAX) - 1) 90 #endif 91 #endif 92 93 #define WEOF ((wint_t)(-1)) 94 95 typedef struct 96 { 97 unsigned __opaque1, __opaque2; 98 } mbstate_t; 99 100 wchar_t *wcscpy (wchar_t *__restrict__, const wchar_t *__restrict__); 101 wchar_t *wcsncpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 102 103 wchar_t *wcscat (wchar_t *__restrict__, const wchar_t *__restrict__); 104 wchar_t *wcsncat (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 105 106 int wcscmp (const wchar_t *, const wchar_t *); 107 int wcsncmp (const wchar_t *, const wchar_t *, size_t); 108 109 int wcscoll(const wchar_t *, const wchar_t *); 110 size_t wcsxfrm (wchar_t *__restrict__, const wchar_t *__restrict__, size_t n); 111 112 wchar_t *wcschr (const wchar_t *, wchar_t); 113 wchar_t *wcsrchr (const wchar_t *, wchar_t); 114 115 size_t wcscspn (const wchar_t *, const wchar_t *); 116 size_t wcsspn (const wchar_t *, const wchar_t *); 117 wchar_t *wcspbrk (const wchar_t *, const wchar_t *); 118 119 wchar_t *wcstok (wchar_t *__restrict__, const wchar_t *__restrict__, wchar_t **__restrict__); 120 121 size_t wcslen (const wchar_t *); 122 123 wchar_t *wcsstr (const wchar_t *__restrict__, const wchar_t *__restrict__); 124 wchar_t *wcswcs (const wchar_t *, const wchar_t *); 125 126 wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); 127 int wmemcmp (const wchar_t *, const wchar_t *, size_t); 128 wchar_t *wmemcpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 129 wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); 130 wchar_t *wmemset (wchar_t *, wchar_t, size_t); 131 132 wint_t btowc (int); 133 int wctob (wint_t); 134 135 int mbsinit (const mbstate_t *); 136 size_t mbrtowc (wchar_t *__restrict__, const char *__restrict__, size_t, mbstate_t *__restrict__); 137 size_t wcrtomb (char *__restrict__, wchar_t, mbstate_t *__restrict__); 138 139 size_t mbrlen (const char *__restrict__, size_t, mbstate_t *__restrict__); 140 141 size_t mbsrtowcs (wchar_t *__restrict__, const char **__restrict__, size_t, mbstate_t *__restrict__); 142 size_t wcsrtombs (char *__restrict__, const wchar_t **__restrict__, size_t, mbstate_t *__restrict__); 143 144 float wcstof (const wchar_t *__restrict__, wchar_t **__restrict__); 145 double wcstod (const wchar_t *__restrict__, wchar_t **__restrict__); 146 long double wcstold (const wchar_t *__restrict__, wchar_t **__restrict__); 147 148 long wcstol (const wchar_t *__restrict__, wchar_t **__restrict__, int); 149 unsigned long wcstoul (const wchar_t *__restrict__, wchar_t **__restrict__, int); 150 151 long long wcstoll (const wchar_t *__restrict__, wchar_t **__restrict__, int); 152 unsigned long long wcstoull (const wchar_t *__restrict__, wchar_t **__restrict__, int); 153 intmax_t wcstoimax (const wchar_t * nptr, wchar_t** endptr , int base); 154 uintmax_t wcstoumax (const wchar_t * nptr, wchar_t** endptr , int base); 155 156 157 int fwide (FILE *, int); 158 159 160 int wprintf (const wchar_t *__restrict__, ...); 161 int fwprintf (FILE *__restrict__, const wchar_t *__restrict__, ...); 162 int swprintf (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, ...); 163 164 int vwprintf (const wchar_t *__restrict__, va_list); 165 int vfwprintf (FILE *__restrict__, const wchar_t *__restrict__, va_list); 166 int vswprintf (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, va_list); 167 168 int wscanf (const wchar_t *__restrict__, ...); 169 int fwscanf (FILE *__restrict__, const wchar_t *__restrict__, ...); 170 int swscanf (const wchar_t *__restrict__, const wchar_t *__restrict__, ...); 171 172 int vwscanf (const wchar_t *__restrict__, va_list); 173 int vfwscanf (FILE *__restrict__, const wchar_t *__restrict__, va_list); 174 int vswscanf (const wchar_t *__restrict__, const wchar_t *__restrict__, va_list); 175 176 wint_t fgetwc (FILE *); 177 wint_t getwc (FILE *); 178 wint_t getwchar (void); 179 180 wint_t fputwc (wchar_t, FILE *); 181 wint_t putwc (wchar_t, FILE *); 182 wint_t putwchar (wchar_t); 183 184 wchar_t *fgetws (wchar_t *__restrict__, int, FILE *__restrict__); 185 int fputws (const wchar_t *__restrict__, FILE *__restrict__); 186 187 wint_t ungetwc (wint_t, FILE *); 188 189 struct tm; 190 size_t wcsftime (wchar_t *__restrict__, size_t, const wchar_t *__restrict__, const struct tm *__restrict__); 191 192 FILE *open_wmemstream(wchar_t **, size_t *); 193 size_t mbsnrtowcs(wchar_t *__restrict__, const char **__restrict__, size_t, size_t, mbstate_t *__restrict__); 194 size_t wcsnrtombs(char *__restrict__, const wchar_t **__restrict__, size_t, size_t, mbstate_t *__restrict__); 195 wchar_t *wcsdup(const wchar_t *); 196 size_t wcsnlen (const wchar_t *, size_t); 197 wchar_t *wcpcpy (wchar_t *__restrict__, const wchar_t *__restrict__); 198 wchar_t *wcpncpy (wchar_t *__restrict__, const wchar_t *__restrict__, size_t); 199 int wcscasecmp(const wchar_t *, const wchar_t *); 200 int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); 201 int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); 202 int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); 203 int wcwidth (wchar_t); 204 int wcswidth (const wchar_t *, size_t); 205 int iswalnum(wint_t); 206 int iswalpha(wint_t); 207 int iswblank(wint_t); 208 int iswcntrl(wint_t); 209 int iswdigit(wint_t); 210 int iswgraph(wint_t); 211 int iswlower(wint_t); 212 int iswprint(wint_t); 213 int iswpunct(wint_t); 214 int iswspace(wint_t); 215 int iswupper(wint_t); 216 int iswxdigit(wint_t); 217 int iswctype(wint_t, wctype_t); 218 wint_t towlower(wint_t); 219 wint_t towupper(wint_t); 220 wctype_t wctype(const char *); 221 222 int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); 223 size_t wcsxfrm_l(wchar_t *__restrict__, const wchar_t *__restrict__, size_t n, locale_t); 224 225 #ifdef __cplusplus 226 } // extern "C" 227 #endif 228 229 #endif // !__LP64__ 230 231 #endif // NDK_ANDROID_SUPPORT_WCHAR_H 232