2
* This file has no copyright assigned and is placed in the Public Domain.
3
* This file is part of the w64 mingw-runtime package.
4
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
6
#ifndef WIN32_LEAN_AND_MEAN
7
#define WIN32_LEAN_AND_MEAN
9
#include "mb_wc_common.h"
15
static int __MINGW_ATTRIB_NONNULL(1) __MINGW_ATTRIB_NONNULL(4)
16
__mbrtowc_cp (wchar_t * __restrict__ pwc, const char * __restrict__ s,
17
size_t n, mbstate_t* __restrict__ ps,
18
const unsigned int cp, const unsigned int mb_max)
26
/* Do the prelim checks */
31
/* The standard doesn't mention this case explicitly. Tell
32
caller that the conversion from a non-null s is incomplete. */
35
/* Save the current shift state, in case we need it in DBCS case. */
36
shift_state.val = *ps;
47
if (shift_state.mbcs[0] != 0)
49
/* Complete the mb char with the trailing byte. */
50
shift_state.mbcs[1] = *s; /* the second byte */
51
if (MultiByteToWideChar(cp, MB_ERR_INVALID_CHARS,
52
shift_state.mbcs, 2, pwc, 1)
55
/* An invalid trailing byte */
61
else if (IsDBCSLeadByteEx (cp, *s))
63
/* If told to translate one byte, just save the leadbyte
70
/* Else translate the first two bytes */
71
else if (MultiByteToWideChar (cp, MB_ERR_INVALID_CHARS,
82
/* Fall through to single byte char */
84
*pwc = (wchar_t)(unsigned char)*s;
86
else if (MultiByteToWideChar (cp, MB_ERR_INVALID_CHARS, s, 1, pwc, 1)
96
mbrtowc (wchar_t * __restrict__ pwc, const char * __restrict__ s,
97
size_t n, mbstate_t* __restrict__ ps)
99
static mbstate_t internal_mbstate = 0;
100
wchar_t byte_bucket = 0;
101
wchar_t* dst = pwc ? pwc : &byte_bucket;
103
return (size_t) __mbrtowc_cp (dst, s, n, ps ? ps : &internal_mbstate,
104
get_codepage(), MB_CUR_MAX);
109
mbsrtowcs (wchar_t* __restrict__ dst, const char ** __restrict__ src,
110
size_t len, mbstate_t* __restrict__ ps)
114
static mbstate_t internal_mbstate = 0;
115
mbstate_t* internal_ps = ps ? ps : &internal_mbstate;
116
const unsigned int cp = get_codepage();
117
const unsigned int mb_max = MB_CUR_MAX;
119
if ( src == NULL || *src == NULL ) /* undefined behavior */
125
&& (ret = __mbrtowc_cp(dst, *src, len - n,
126
internal_ps, cp, mb_max))
134
if (n < len && ret == 0)
140
wchar_t byte_bucket = 0;
142
&& (ret = __mbrtowc_cp (&byte_bucket, *src, mb_max,
143
internal_ps, cp, mb_max))
154
mbrlen (const char * __restrict__ s, size_t n,
155
mbstate_t * __restrict__ ps)
157
static mbstate_t s_mbstate = 0;
158
wchar_t byte_bucket = 0;
159
return __mbrtowc_cp (&byte_bucket, s, n, (ps) ? ps : &s_mbstate,
160
get_codepage(), MB_CUR_MAX);