| 1 | /** |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. |
| 3 | * This file is part of the mingw-w64 runtime package. |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 | */ |
| 6 | |
| 7 | #define __LARGE_MBSTATE_T |
| 8 | |
| 9 | #include <limits.h> /* MB_LEN_MAX */ |
| 10 | #include <wchar.h> |
| 11 | #include <stdio.h> /* EOF */ |
| 12 | #include <stdlib.h> /* MB_CUR_MAX */ |
| 13 | |
| 14 | wint_t btowc (int c) |
| 15 | { |
| 16 | if (c == EOF) |
| 17 | return (WEOF); |
| 18 | |
| 19 | /* Use dummy string so that mbrtowc will never return (size_t)-2 */ |
| 20 | char str[MB_LEN_MAX] = {(unsigned char) c, 0, 0, 0, 0}; |
| 21 | |
| 22 | wint_t wc = WEOF; |
| 23 | mbstate_t state = {0}; |
| 24 | |
| 25 | if (mbrtowc (&wc, (char *) str, MB_CUR_MAX, &state) == (size_t) -1) { |
| 26 | return WEOF; |
| 27 | } |
| 28 | |
| 29 | return wc; |
| 30 | } |
| 31 | |
| 32 | wint_t (__cdecl *__MINGW_IMP_SYMBOL (btowc)) (int) = btowc; |