1 /* 2 * Copyright 2008-2011 Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _WCHAR_H 6 #define _WCHAR_H 7 8 9 #include <limits.h> 10 #include <stddef.h> 11 #include <stdio.h> 12 13 14 /* stddef.h is not supposed to define wint_t, but gcc 2.95.3's one does. 15 * In all other cases we will do that. */ 16 #ifndef _WINT_T 17 #define _WINT_T 18 19 #ifndef __WINT_TYPE__ 20 #define __WINT_TYPE__ unsigned int 21 #endif 22 23 typedef __WINT_TYPE__ wint_t; 24 25 #endif /* _WINT_T */ 26 27 typedef int wctype_t; 28 29 typedef struct { 30 void* converter; 31 char charset[64]; 32 unsigned int count; 33 char data[1024 + 8]; // 1024 bytes for data, 8 for alignment space 34 } mbstate_t; 35 36 37 #define WEOF ((wint_t)(-1)) 38 39 #define WCHAR_MIN 0x00000000UL 40 #define WCHAR_MAX 0x7FFFFFFFUL 41 42 /* 43 * Haiku is always using UTF32 in wchars, other encodings can be handled 44 * by converting to/from wchar by means of mbrtowc() or wcrtomb(). 45 */ 46 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 extern wint_t btowc(int); 53 54 extern wint_t fgetwc(FILE *stream); 55 extern wchar_t *fgetws(wchar_t *dest, int destLength, FILE *stream); 56 extern wint_t fputwc(wchar_t wc, FILE *stream); 57 extern int fputws(const wchar_t *wcs, FILE *stream); 58 extern int fwide(FILE *stream, int mode); 59 extern int fwprintf(FILE *stream, const wchar_t *format, ...); 60 extern int fwscanf(FILE *stream, const wchar_t *format, ...); 61 extern wint_t getwc(FILE *stream); 62 extern wint_t getwchar(void); 63 64 extern size_t mbrlen(const char *s, size_t n, mbstate_t *mbState); 65 extern size_t mbrtowc(wchar_t *dest, const char *src, size_t srcLength, 66 mbstate_t *mbState); 67 extern int mbsinit(const mbstate_t *mbState); 68 extern size_t mbsnrtowcs(wchar_t *dest, const char **src, size_t srcLength, 69 size_t destLength, mbstate_t *mbState); 70 extern size_t mbsrtowcs(wchar_t *dest, const char **src, size_t destLength, 71 mbstate_t *mbState); 72 73 extern wint_t putwc(wchar_t wc, FILE *stream); 74 extern wint_t putwchar(wchar_t wc); 75 76 extern int swprintf(wchar_t *dest, size_t destLength, 77 const wchar_t *format, ...); 78 extern int swscanf(const wchar_t *wcs, const wchar_t *format, ...); 79 80 extern wint_t ungetwc(wint_t wc, FILE *stream); 81 82 extern int vfwprintf(FILE *stream, const wchar_t *format, va_list arg); 83 extern int vfwscanf(FILE *stream, const wchar_t *format, va_list arg); 84 extern int vswprintf(wchar_t *dest, size_t destLength, 85 const wchar_t *format, va_list arg); 86 extern int vswscanf(const wchar_t *wcs, const wchar_t *format, 87 va_list arg); 88 extern int vwprintf(const wchar_t *format, va_list arg); 89 extern int vwscanf(const wchar_t *format, va_list arg); 90 91 extern wchar_t *wcpcpy(wchar_t *dest, const wchar_t *src); 92 extern wchar_t *wcpncpy(wchar_t *dest, const wchar_t *src, size_t srcLength); 93 extern size_t wcrtomb(char *dest, wchar_t wc, mbstate_t *mbState); 94 extern int wcscasecmp(const wchar_t *wcs1, const wchar_t *wcs2); 95 extern wchar_t *wcscat(wchar_t *dest, const wchar_t *src); 96 extern wchar_t *wcschr(const wchar_t *wcs, wchar_t wc); 97 #ifdef __USE_GNU 98 extern wchar_t *wcschrnul(const wchar_t *wcs, wchar_t wc); 99 #endif 100 extern int wcscmp(const wchar_t *wcs1, const wchar_t *wcs2); 101 extern int wcscoll(const wchar_t *wcs1, const wchar_t *wcs2); 102 extern wchar_t *wcscpy(wchar_t *dest, const wchar_t *src); 103 extern size_t wcscspn(const wchar_t *wcs, const wchar_t *reject); 104 extern wchar_t *wcsdup(const wchar_t *wcs); 105 extern size_t wcsftime(wchar_t *dest, size_t destLength, 106 const wchar_t *format, const struct tm *time); 107 extern size_t wcslcat(wchar_t *dest, const wchar_t *src, size_t maxLength); 108 extern size_t wcslcpy(wchar_t *dest, const wchar_t *src, size_t maxLength); 109 extern size_t wcslen(const wchar_t *wcs); 110 extern int wcsncasecmp(const wchar_t *wcs1, const wchar_t *wcs2, 111 size_t maxLength); 112 extern wchar_t *wcsncat(wchar_t *dest, const wchar_t *src, size_t srcLength); 113 extern int wcsncmp(const wchar_t *wcs1, const wchar_t *wcs2, 114 size_t length); 115 extern wchar_t *wcsncpy(wchar_t *dest, const wchar_t *src, size_t srcLength); 116 extern size_t wcsnlen(const wchar_t *wcs, size_t maxLength); 117 extern size_t wcsnrtombs(char *dest, const wchar_t **src, size_t srcLength, 118 size_t destLength, mbstate_t *mbState); 119 extern wchar_t *wcspbrk(const wchar_t *wcs, const wchar_t *accept); 120 extern wchar_t *wcsrchr(const wchar_t *wcs, wchar_t wc); 121 extern size_t wcsrtombs(char *dest, const wchar_t **src, size_t destLength, 122 mbstate_t *mbState); 123 extern size_t wcsspn(const wchar_t *wcs, const wchar_t *accept); 124 extern wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle); 125 extern double wcstod(const wchar_t *wcs, wchar_t **endPtr); 126 extern float wcstof(const wchar_t *wcs, wchar_t **endPtr); 127 extern wchar_t *wcstok(wchar_t *wcs1, const wchar_t *wcs2, wchar_t **ptr); 128 extern long wcstol(const wchar_t *wcs, wchar_t **endPtr, int base); 129 extern long double wcstold(const wchar_t *wcs, wchar_t **endPtr); 130 extern long long wcstoll(const wchar_t *wcs, wchar_t **endPtr, int base); 131 extern unsigned long wcstoul(const wchar_t *wcs, wchar_t **endPtr, 132 int base); 133 extern unsigned long long wcstoull(const wchar_t *wcs, wchar_t **endPtr, 134 int base); 135 extern wchar_t *wcswcs(const wchar_t *haystack, const wchar_t *needle); 136 extern int wcswidth(const wchar_t *wcs, size_t length); 137 extern size_t wcsxfrm(wchar_t *dest, const wchar_t *src, size_t destLength); 138 extern int wctob(wint_t wc); 139 extern int wcwidth(wchar_t wc); 140 extern wchar_t *wmemchr(const wchar_t *wcs, wchar_t wc, size_t n); 141 extern int wmemcmp(const wchar_t *wcs1, const wchar_t *wcs2, size_t n); 142 extern wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t n); 143 extern wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t n); 144 #ifdef __USE_GNU 145 extern wchar_t *wmempcpy(wchar_t *dest, const wchar_t *src, size_t n); 146 #endif 147 extern wchar_t *wmemset(wchar_t *dest, wchar_t wc, size_t n); 148 149 extern int wprintf(const wchar_t *format, ...); 150 extern int wscanf(const wchar_t *format, ...); 151 152 #ifdef __cplusplus 153 } 154 #endif 155 156 #endif /* _WCHAR_H */ 157