1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 #ifndef _WCHAR_H_ 29 #define _WCHAR_H_ 30 31 #include <sys/cdefs.h> 32 #include <stdio.h> 33 34 /* wchar_t is required in stdlib.h according to POSIX */ 35 #define __need___wchar_t 36 #include <stddef.h> 37 38 #include <stdarg.h> 39 #include <time.h> 40 #include <malloc.h> 41 42 #include <stddef.h> 43 44 /* IMPORTANT: Any code that relies on wide character support is essentially 45 * non-portable and/or broken. the only reason this header exist 46 * is because I'm really a nice guy. However, I'm not nice enough 47 * to provide you with a real implementation. instead wchar_t == char 48 * and all wc functions are stubs to their "normal" equivalent... 49 */ 50 51 __BEGIN_DECLS 52 53 typedef __WINT_TYPE__ wint_t; 54 typedef struct { int dummy; } mbstate_t; 55 56 typedef enum { 57 WC_TYPE_INVALID = 0, 58 WC_TYPE_ALNUM, 59 WC_TYPE_ALPHA, 60 WC_TYPE_BLANK, 61 WC_TYPE_CNTRL, 62 WC_TYPE_DIGIT, 63 WC_TYPE_GRAPH, 64 WC_TYPE_LOWER, 65 WC_TYPE_PRINT, 66 WC_TYPE_PUNCT, 67 WC_TYPE_SPACE, 68 WC_TYPE_UPPER, 69 WC_TYPE_XDIGIT, 70 WC_TYPE_MAX 71 } wctype_t; 72 73 /* TECHNICAL NOTE: This is tricky! 74 * 75 * Due to the following inclusion chain: 76 * <wchar.h> -> <stdio.h> -> <sys/types.h> -> <stdint.h> 77 * 78 * WCHAR_MIN / WCHAR_MAX will already be defined to INT32_MIN / INT32_MAX 79 * when reaching this line in the following cases: 80 * - Compiling C source code. 81 * - Compiling C++ source code AND having __STDC_LIMIT_MACROS defined. 82 * 83 * When _WCHAR_IS_8BIT is defined, it should emulate the old behaviour. 84 * which was to (conditionally) set the values to 0 and 255, respectively. 85 */ 86 #ifndef WCHAR_MAX 87 # ifdef _WCHAR_IS_8BIT 88 # define WCHAR_MAX 255 89 # define WCHAR_MIN 0 90 # else 91 /* Same values as INT32_MIN/INT32_MAX, without including <stdint.h> */ 92 # define WCHAR_MAX (2147483647) 93 # define WCHAR_MIN (-1-2147483647) 94 # endif 95 #endif 96 97 /* Similarly, WEOF used to be defined as simply -1, which is 98 * invalid (the standard mandates that the expression must have wint_t 99 * type). There is no difference in C, but there is one in C++!! 100 * 101 * Revert to the old broken behaviour is _WCHAR_IS_8BIT is defined. 102 */ 103 #ifdef _WCHAR_IS_8BIT 104 #define WEOF (-1) 105 #else 106 #define WEOF ((wint_t)-1) 107 #endif 108 109 extern wint_t btowc(int); 110 extern int fwprintf(FILE *, const wchar_t *, ...); 111 extern int fwscanf(FILE *, const wchar_t *, ...); 112 extern int iswalnum(wint_t); 113 extern int iswalpha(wint_t); 114 extern int iswcntrl(wint_t); 115 extern int iswdigit(wint_t); 116 extern int iswgraph(wint_t); 117 extern int iswlower(wint_t); 118 extern int iswprint(wint_t); 119 extern int iswpunct(wint_t); 120 extern int iswspace(wint_t); 121 extern int iswupper(wint_t); 122 extern int iswxdigit(wint_t); 123 extern int iswctype(wint_t, wctype_t); 124 extern wint_t fgetwc(FILE *); 125 extern wchar_t *fgetws(wchar_t *, int, FILE *); 126 extern wint_t fputwc(wchar_t, FILE *); 127 extern int fputws(const wchar_t *, FILE *); 128 extern int fwide(FILE *, int); 129 extern wint_t getwc(FILE *); 130 extern wint_t getwchar(void); 131 extern int mbsinit(const mbstate_t *); 132 extern size_t mbrlen(const char *, size_t, mbstate_t *); 133 extern size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *); 134 extern size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *); 135 extern wint_t putwc(wchar_t, FILE *); 136 extern wint_t putwchar(wchar_t); 137 extern int swprintf(wchar_t *, size_t, const wchar_t *, ...); 138 extern int swscanf(const wchar_t *, const wchar_t *, ...); 139 extern wint_t towlower(wint_t); 140 extern wint_t towupper(wint_t); 141 extern wint_t ungetwc(wint_t, FILE *); 142 extern int vfwprintf(FILE *, const wchar_t *, va_list); 143 extern int vwprintf(const wchar_t *, va_list); 144 extern int vswprintf(wchar_t *, size_t, const wchar_t *, va_list); 145 extern size_t wcrtomb(char *, wchar_t, mbstate_t *); 146 extern wchar_t *wcscat(wchar_t *, const wchar_t *); 147 extern wchar_t *wcschr(const wchar_t *, wchar_t); 148 extern int wcscmp(const wchar_t *, const wchar_t *); 149 extern int wcscoll(const wchar_t *, const wchar_t *); 150 extern wchar_t *wcscpy(wchar_t *, const wchar_t *); 151 extern size_t wcscspn(const wchar_t *, const wchar_t *); 152 extern size_t wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *); 153 extern size_t wcslen(const wchar_t *); 154 extern wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t); 155 extern int wcsncmp(const wchar_t *, const wchar_t *, size_t); 156 extern wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t); 157 extern wchar_t *wcspbrk(const wchar_t *, const wchar_t *); 158 extern wchar_t *wcsrchr(const wchar_t *, wchar_t); 159 extern size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *); 160 extern size_t wcsspn(const wchar_t *, const wchar_t *); 161 extern wchar_t *wcsstr(const wchar_t *, const wchar_t *); 162 extern double wcstod(const wchar_t *, wchar_t **); 163 extern wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **); 164 extern long int wcstol(const wchar_t *, wchar_t **, int); 165 extern unsigned long int wcstoul(const wchar_t *, wchar_t **, int); 166 extern wchar_t *wcswcs(const wchar_t *, const wchar_t *); 167 extern int wcswidth(const wchar_t *, size_t); 168 extern size_t wcsxfrm(wchar_t *, const wchar_t *, size_t); 169 extern int wctob(wint_t); 170 extern wctype_t wctype(const char *); 171 extern int wcwidth(wchar_t); 172 extern wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); 173 extern int wmemcmp(const wchar_t *, const wchar_t *, size_t); 174 extern wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t); 175 extern wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); 176 extern wchar_t *wmemset(wchar_t *, wchar_t, size_t); 177 extern int wprintf(const wchar_t *, ...); 178 extern int wscanf(const wchar_t *, ...); 179 180 /* No really supported. These are just for making libstdc++-v3 happy. */ 181 typedef void *wctrans_t; 182 extern wint_t towctrans(wint_t, wctrans_t); 183 extern wctrans_t wctrans (const char *); 184 185 __END_DECLS 186 187 #endif /* _WCHAR_H_ */ 188