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#ifndef WIN32_LEAN_AND_MEAN
10#define WIN32_LEAN_AND_MEAN
11#endif
12#include <locale.h>
13#include <limits.h>
14#include <wchar.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <errno.h>
18#include <windows.h>
19
20int wctob (wint_t wc)
21{
22 /* Return early */
23 if (IS_LOW_SURROGATE (wc) || IS_HIGH_SURROGATE (wc) || wc == WEOF) {
24 return EOF;
25 }
26
27 mbstate_t state = {0};
28 /* Buffer large enough to hold any multibyte character */
29 char mbc[MB_LEN_MAX];
30
31 size_t length = wcrtomb (mbc, wc, &state);
32 if (length > 1) {
33 return EOF;
34 }
35
36 return (unsigned char) mbc[0];
37}
38
39int (__cdecl *__MINGW_IMP_SYMBOL (wctob)) (wint_t) = wctob;