2 * msvcrt.dll mbcs functions
4 * Copyright 1999 Alexandre Julliard
5 * Copyright 2000 Jon Griffths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Not currently binary compatible with win32. MSVCRT_mbctype must be
23 * populated correctly and the ismb* functions should reference it.
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
35 unsigned char MSVCRT_mbctype
[257] = { 0 };
37 /* It seems that the data about valid trail bytes is not available from kernel32
38 * so we have to store is here. The format is the same as for lead bytes in CPINFO */
39 struct cp_extra_info_t
42 BYTE TrailBytes
[MAX_LEADBYTES
];
45 static struct cp_extra_info_t g_cpextrainfo
[] =
47 {932, {0x40, 0x7e, 0x80, 0xfc, 0, 0}},
48 {936, {0x40, 0xfe, 0, 0}},
49 {949, {0x41, 0xfe, 0, 0}},
50 {950, {0x40, 0x7e, 0xa1, 0xfe, 0, 0}},
51 {1361, {0x31, 0x7e, 0x81, 0xfe, 0, 0}},
52 {20932, {1, 255, 0, 0}}, /* seems to give different results on different systems */
53 {0, {1, 255, 0, 0}} /* match all with FIXME */
56 /* Maps cp932 single byte character to multi byte character */
57 static const unsigned char mbbtombc_932
[] = {
58 0x40,0x49,0x68,0x94,0x90,0x93,0x95,0x66,0x69,0x6a,0x96,0x7b,0x43,0x7c,0x44,0x5e,
59 0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x46,0x47,0x83,0x81,0x84,0x48,
60 0x97,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,
61 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x76,
62 0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x51,0x65,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
63 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x50,
64 0x42,0x75,0x76,0x41,0x45,0x92,0x40,0x42,0x44,0x46,0x48,0x83,0x85,0x87,0x62,
65 0x5b,0x41,0x43,0x45,0x47,0x49,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,
66 0x5e,0x60,0x63,0x65,0x67,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x71,0x74,0x77,0x7a,0x7d,
67 0x7e,0x80,0x81,0x82,0x84,0x86,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8f,0x93,0x4a,0x4b };
69 /* Maps multibyte cp932 punctuation marks to single byte equivalents */
70 static const unsigned char mbctombb_932_punct
[] = {
71 0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e,
72 0x7e,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x00,0x00,0x2f,0x00,
73 0x00,0x00,0x7c,0x00,0x00,0x60,0x27,0x00,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,0x7b,
74 0x7d,0x00,0x00,0x00,0x00,0xa2,0xa3,0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,0x00,
75 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5c,
76 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40};
78 /* Maps multibyte cp932 hiragana/katakana to single-byte equivalents */
79 static const unsigned char mbctombb_932_kana
[] = {
80 0xa7,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8,0xb8,
81 0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0,0xc0,
82 0xc1,0xc1,0xaf,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xca,
83 0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0,0xd1,
84 0xd2,0xd3,0xac,0xd4,0xad,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xb2,
85 0xb4,0xa6,0xdd,0xb3,0xb6,0xb9};
87 static MSVCRT_wchar_t
msvcrt_mbc_to_wc_l(unsigned int ch
, MSVCRT__locale_t locale
)
89 MSVCRT_pthreadmbcinfo mbcinfo
;
95 mbcinfo
= locale
->mbcinfo
;
97 mbcinfo
= get_mbcinfo();
103 mbch
[0] = (ch
>> 8) & 0xff;
107 if (!MultiByteToWideChar(mbcinfo
->mbcodepage
, 0, mbch
, n_chars
, &chW
, 1))
109 WARN("MultiByteToWideChar failed on %x\n", ch
);
115 static MSVCRT_wchar_t
msvcrt_mbc_to_wc(unsigned int ch
)
117 return msvcrt_mbc_to_wc_l(ch
, NULL
);
120 static inline MSVCRT_size_t
u_strlen( const unsigned char *str
)
122 return strlen( (const char*) str
);
125 static inline unsigned char* u_strncat( unsigned char* dst
, const unsigned char* src
, MSVCRT_size_t len
)
127 return (unsigned char*)strncat( (char*)dst
, (const char*)src
, len
);
130 static inline int u_strcmp( const unsigned char *s1
, const unsigned char *s2
)
132 return MSVCRT_strcmp( (const char*)s1
, (const char*)s2
);
135 static inline int u_strcasecmp( const unsigned char *s1
, const unsigned char *s2
)
137 return MSVCRT__stricmp( (const char*)s1
, (const char*)s2
);
140 static inline int u_strncmp( const unsigned char *s1
, const unsigned char *s2
, MSVCRT_size_t len
)
142 return MSVCRT_strncmp( (const char*)s1
, (const char*)s2
, len
);
145 static inline int u_strncasecmp( const unsigned char *s1
, const unsigned char *s2
, MSVCRT_size_t len
)
147 return MSVCRT__strnicmp( (const char*)s1
, (const char*)s2
, len
);
150 static inline unsigned char *u_strchr( const unsigned char *s
, unsigned char x
)
152 return (unsigned char*) strchr( (const char*)s
, x
);
155 static inline unsigned char *u_strrchr( const unsigned char *s
, unsigned char x
)
157 return (unsigned char*) strrchr( (const char*)s
, x
);
160 static inline unsigned char *u__strset( unsigned char *s
, unsigned char c
)
162 return (unsigned char*) _strset( (char*)s
, c
);
165 static inline unsigned char *u__strnset( unsigned char *s
, unsigned char c
, MSVCRT_size_t len
)
167 return (unsigned char*) MSVCRT__strnset( (char*)s
, c
, len
);
170 /*********************************************************************
171 * __p__mbctype (MSVCRT.@)
173 unsigned char* CDECL
__p__mbctype(void)
175 return get_mbcinfo()->mbctype
;
178 /*********************************************************************
179 * __p___mb_cur_max(MSVCRT.@)
181 int* CDECL
__p___mb_cur_max(void)
183 return &get_locinfo()->mb_cur_max
;
186 /*********************************************************************
187 * ___mb_cur_max_func(MSVCRT.@)
189 int CDECL
MSVCRT____mb_cur_max_func(void)
191 return get_locinfo()->mb_cur_max
;
195 /*********************************************************************
196 * ___mb_cur_max_l_func (MSVCR80.@)
198 int CDECL
___mb_cur_max_l_func(MSVCRT__locale_t locale
)
200 MSVCRT_pthreadlocinfo locinfo
;
203 locinfo
= get_locinfo();
205 locinfo
= locale
->locinfo
;
207 return locinfo
->mb_cur_max
;
211 /*********************************************************************
212 * INTERNAL: _setmbcp_l
214 int _setmbcp_l(int cp
, LCID lcid
, MSVCRT_pthreadmbcinfo mbcinfo
)
216 const char format
[] = ".%d";
223 WCHAR bufW
[256], lowW
[256], upW
[256];
229 mbcinfo
= get_mbcinfo();
240 newcp
= get_locinfo()->lc_codepage
;
243 /* fall through (C locale) */
245 newcp
= 20127; /* ASCII */
253 MSVCRT_sprintf(bufA
, format
, newcp
);
254 mbcinfo
->mblcid
= MSVCRT_locale_to_LCID(bufA
, NULL
, NULL
);
256 mbcinfo
->mblcid
= lcid
;
259 if(mbcinfo
->mblcid
== -1)
261 WARN("Can't assign LCID to codepage (%d)\n", mbcinfo
->mblcid
);
265 if (!GetCPInfo(newcp
, &cpi
))
267 WARN("Codepage %d not found\n", newcp
);
268 *MSVCRT__errno() = MSVCRT_EINVAL
;
272 /* setup the _mbctype */
273 memset(mbcinfo
->mbctype
, 0, sizeof(unsigned char[257]));
274 memset(mbcinfo
->mbcasemap
, 0, sizeof(unsigned char[256]));
276 bytes
= cpi
.LeadByte
;
277 while (bytes
[0] || bytes
[1])
279 for (i
= bytes
[0]; i
<= bytes
[1]; i
++)
280 mbcinfo
->mbctype
[i
+ 1] |= _M1
;
284 if (cpi
.MaxCharSize
> 1)
286 /* trail bytes not available through kernel32 but stored in a structure in msvcrt */
287 struct cp_extra_info_t
*cpextra
= g_cpextrainfo
;
289 mbcinfo
->ismbcodepage
= 1;
292 if (cpextra
->cp
== 0 || cpextra
->cp
== newcp
)
294 if (cpextra
->cp
== 0)
295 FIXME("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp
);
297 bytes
= cpextra
->TrailBytes
;
298 while (bytes
[0] || bytes
[1])
300 for (i
= bytes
[0]; i
<= bytes
[1]; i
++)
301 mbcinfo
->mbctype
[i
+ 1] |= _M2
;
310 mbcinfo
->ismbcodepage
= 0;
312 /* we can't use GetStringTypeA directly because we don't have a locale - only a code page
315 for (i
= 0; i
< 256; i
++)
316 if (!(mbcinfo
->mbctype
[i
+ 1] & _M1
))
317 bufA
[charcount
++] = i
;
319 ret
= MultiByteToWideChar(newcp
, 0, bufA
, charcount
, bufW
, charcount
);
320 if (ret
!= charcount
)
321 ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp
, ret
, charcount
, GetLastError());
323 GetStringTypeW(CT_CTYPE1
, bufW
, charcount
, chartypes
);
324 LCMapStringW(lcid
, LCMAP_LOWERCASE
, bufW
, charcount
, lowW
, charcount
);
325 LCMapStringW(lcid
, LCMAP_UPPERCASE
, bufW
, charcount
, upW
, charcount
);
328 for (i
= 0; i
< 256; i
++)
329 if (!(mbcinfo
->mbctype
[i
+ 1] & _M1
))
331 if (chartypes
[charcount
] & C1_UPPER
)
333 mbcinfo
->mbctype
[i
+ 1] |= _SBUP
;
334 bufW
[charcount
] = lowW
[charcount
];
336 else if (chartypes
[charcount
] & C1_LOWER
)
338 mbcinfo
->mbctype
[i
+ 1] |= _SBLOW
;
339 bufW
[charcount
] = upW
[charcount
];
344 ret
= WideCharToMultiByte(newcp
, 0, bufW
, charcount
, bufA
, charcount
, NULL
, NULL
);
345 if (ret
!= charcount
)
346 ERR("WideCharToMultiByte failed for cp %d, ret=%d (exp %d), error=%d\n", newcp
, ret
, charcount
, GetLastError());
349 for (i
= 0; i
< 256; i
++)
351 if(!(mbcinfo
->mbctype
[i
+ 1] & _M1
))
353 if(mbcinfo
->mbctype
[i
] & (C1_UPPER
|C1_LOWER
))
354 mbcinfo
->mbcasemap
[i
] = bufA
[charcount
];
359 if (newcp
== 932) /* CP932 only - set _MP and _MS */
361 /* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
362 * and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes
363 * it hard. As this is set only for codepage 932 we hardcode it what gives
364 * also faster execution.
366 for (i
= 161; i
<= 165; i
++)
367 mbcinfo
->mbctype
[i
+ 1] |= _MP
;
368 for (i
= 166; i
<= 223; i
++)
369 mbcinfo
->mbctype
[i
+ 1] |= _MS
;
372 mbcinfo
->mbcodepage
= newcp
;
373 if(MSVCRT_locale
&& mbcinfo
== MSVCRT_locale
->mbcinfo
)
374 memcpy(MSVCRT_mbctype
, MSVCRT_locale
->mbcinfo
->mbctype
, sizeof(MSVCRT_mbctype
));
379 /*********************************************************************
380 * _setmbcp (MSVCRT.@)
382 int CDECL
_setmbcp(int cp
)
384 return _setmbcp_l(cp
, -1, NULL
);
387 /*********************************************************************
388 * _getmbcp (MSVCRT.@)
390 int CDECL
_getmbcp(void)
392 return get_mbcinfo()->mbcodepage
;
395 /*********************************************************************
396 * _mbsnextc_l(MSVCRT.@)
398 unsigned int CDECL
_mbsnextc_l(const unsigned char* str
, MSVCRT__locale_t locale
)
400 if(_ismbblead_l(*str
, locale
))
401 return *str
<< 8 | str
[1];
405 /*********************************************************************
406 * _mbsnextc(MSVCRT.@)
408 unsigned int CDECL
_mbsnextc(const unsigned char* str
)
410 return _mbsnextc_l(str
, NULL
);
413 /*********************************************************************
414 * _mbctolower(MSVCRT.@)
416 unsigned int CDECL
_mbctolower(unsigned int c
)
420 FIXME("Handle MBC chars\n");
423 return MSVCRT__tolower_l(c
, NULL
); /* ASCII CP or SB char */
426 /*********************************************************************
427 * _mbctoupper(MSVCRT.@)
429 unsigned int CDECL
_mbctoupper(unsigned int c
)
433 FIXME("Handle MBC chars\n");
436 return MSVCRT__toupper_l(c
, NULL
); /* ASCII CP or SB char */
439 /*********************************************************************
440 * _mbctombb (MSVCRT.@)
442 unsigned int CDECL
_mbctombb(unsigned int c
)
446 if(get_mbcinfo()->mbcodepage
== 932)
448 if(c
>= 0x829f && c
<= 0x82f1) /* Hiragana */
449 return mbctombb_932_kana
[c
- 0x829f];
450 if(c
>= 0x8340 && c
<= 0x8396 && c
!= 0x837f) /* Katakana */
451 return mbctombb_932_kana
[c
- 0x8340 - (c
>= 0x837f ? 1 : 0)];
452 if(c
>= 0x8140 && c
<= 0x8197) /* Punctuation */
454 value
= mbctombb_932_punct
[c
- 0x8140];
455 return value
? value
: c
;
457 if((c
>= 0x824f && c
<= 0x8258) || /* Fullwidth digits */
458 (c
>= 0x8260 && c
<= 0x8279)) /* Fullwidth capitals letters */
460 if(c
>= 0x8281 && c
<= 0x829a) /* Fullwidth small letters */
462 /* all other cases return c */
467 /*********************************************************************
468 * _mbcjistojms(MSVCRT.@)
470 * Converts a jis character to sjis.
471 * Based on description from
472 * http://www.slayers.ne.jp/~oouchi/code/jistosjis.html
474 unsigned int CDECL
_mbcjistojms(unsigned int c
)
476 /* Conversion takes place only when codepage is 932.
477 In all other cases, c is returned unchanged */
478 if(get_mbcinfo()->mbcodepage
== 932)
480 if(HIBYTE(c
) >= 0x21 && HIBYTE(c
) <= 0x7e &&
481 LOBYTE(c
) >= 0x21 && LOBYTE(c
) <= 0x7e)
488 if(LOBYTE(c
) >= 0x7F)
491 c
= (((HIBYTE(c
) - 0x21)/2 + 0x81) << 8) | LOBYTE(c
);
497 return 0; /* Codepage is 932, but c can't be converted */
503 /*********************************************************************
504 * _mbcjmstojis(MSVCRT.@)
506 * Converts a sjis character to jis.
508 unsigned int CDECL
_mbcjmstojis(unsigned int c
)
510 /* Conversion takes place only when codepage is 932.
511 In all other cases, c is returned unchanged */
512 if(get_mbcinfo()->mbcodepage
== 932)
514 if(_ismbclegal(c
) && HIBYTE(c
) < 0xf0)
516 if(HIBYTE(c
) >= 0xe0)
519 c
= (((HIBYTE(c
) - 0x81)*2 + 0x21) << 8) | LOBYTE(c
);
530 return 0; /* Codepage is 932, but c can't be converted */
536 /*********************************************************************
539 unsigned char* CDECL
_mbsdec(const unsigned char* start
, const unsigned char* cur
)
544 if(get_mbcinfo()->ismbcodepage
)
545 return (unsigned char *)(_ismbstrail(start
,cur
-1) ? cur
- 2 : cur
-1);
547 return (unsigned char *)cur
- 1; /* ASCII CP or SB char */
550 /*********************************************************************
553 unsigned int CDECL
_mbclen(const unsigned char* str
)
555 return _ismbblead(*str
) ? 2 : 1;
558 /*********************************************************************
561 unsigned char* CDECL
_mbsinc(const unsigned char* str
)
563 return (unsigned char *)(str
+ _mbclen(str
));
566 /*********************************************************************
569 unsigned char* CDECL
_mbsninc(const unsigned char* str
, MSVCRT_size_t num
)
574 while (num
> 0 && *str
)
576 if (_ismbblead(*str
))
586 return (unsigned char*)str
;
589 /*********************************************************************
590 * _mbsnlen_l(MSVCRT.@)
592 MSVCRT_size_t CDECL
_mbsnlen_l(const unsigned char *str
,
593 MSVCRT_size_t maxsize
, MSVCRT__locale_t locale
)
595 MSVCRT_pthreadmbcinfo mbcinfo
;
596 MSVCRT_size_t i
= 0, len
= 0;
599 mbcinfo
= get_mbcinfo();
601 mbcinfo
= locale
->mbcinfo
;
603 if(!mbcinfo
->ismbcodepage
)
604 return MSVCRT_strnlen((const char*)str
, maxsize
);
606 while(i
<maxsize
&& str
[i
])
608 if (_ismbblead_l(str
[i
], locale
))
611 if (!str
[i
]) /* count only full chars */
617 return i
< maxsize
? len
: maxsize
;
620 /*********************************************************************
623 MSVCRT_size_t CDECL
_mbslen(const unsigned char* str
)
625 return _mbsnlen_l(str
, -1, NULL
);
628 /*********************************************************************
629 * _mbslen_l(MSVCRT.@)
631 MSVCRT_size_t CDECL
_mbslen_l(const unsigned char* str
, MSVCRT__locale_t locale
)
633 return _mbsnlen_l(str
, -1, locale
);
636 /*********************************************************************
639 MSVCRT_size_t CDECL
_mbsnlen(const unsigned char* str
, MSVCRT_size_t maxsize
)
641 return _mbsnlen_l(str
, maxsize
, NULL
);
644 /*********************************************************************
645 * _mbccpy_s_l(MSVCRT.@)
647 int CDECL
_mbccpy_s_l(unsigned char* dest
, MSVCRT_size_t maxsize
,
648 int *copied
, const unsigned char* src
, MSVCRT__locale_t locale
)
650 if(copied
) *copied
= 0;
651 if(!MSVCRT_CHECK_PMT(dest
!= NULL
&& maxsize
>= 1)) return MSVCRT_EINVAL
;
653 if(!MSVCRT_CHECK_PMT(src
!= NULL
)) return MSVCRT_EINVAL
;
655 if(_ismbblead_l(*src
, locale
)) {
657 if(copied
) *copied
= 1;
658 *MSVCRT__errno() = MSVCRT_EILSEQ
;
659 return MSVCRT_EILSEQ
;
663 MSVCRT_INVALID_PMT("dst buffer is too small", MSVCRT_ERANGE
);
664 return MSVCRT_ERANGE
;
669 if(copied
) *copied
= 2;
672 if(copied
) *copied
= 1;
678 /*********************************************************************
681 void CDECL
_mbccpy(unsigned char* dest
, const unsigned char* src
)
683 _mbccpy_s_l(dest
, 2, NULL
, src
, NULL
);
686 /*********************************************************************
687 * _mbccpy_l(MSVCRT.@)
689 void CDECL
_mbccpy_l(unsigned char* dest
, const unsigned char* src
,
690 MSVCRT__locale_t locale
)
692 _mbccpy_s_l(dest
, 2, NULL
, src
, locale
);
695 /*********************************************************************
696 * _mbccpy_s(MSVCRT.@)
698 int CDECL
_mbccpy_s(unsigned char* dest
, MSVCRT_size_t maxsize
,
699 int *copied
, const unsigned char* src
)
701 return _mbccpy_s_l(dest
, maxsize
, copied
, src
, NULL
);
704 /*********************************************************************
707 * The parameter n is the number or characters to copy, not the size of
708 * the buffer. Use _mbsnbcpy for a function analogical to strncpy
710 unsigned char* CDECL
_mbsncpy(unsigned char* dst
, const unsigned char* src
, MSVCRT_size_t n
)
712 unsigned char* ret
= dst
;
715 if (get_mbcinfo()->ismbcodepage
)
720 if (_ismbblead(*src
))
740 if (!(*dst
++ = *src
++)) break;
743 while (n
--) *dst
++ = 0;
747 /*********************************************************************
748 * _mbsnbcpy_s_l(MSVCRT.@)
750 * Unlike _mbsnbcpy this function does not pad the rest of the dest
753 int CDECL
_mbsnbcpy_s_l(unsigned char* dst
, MSVCRT_size_t size
,
754 const unsigned char* src
, MSVCRT_size_t n
, MSVCRT__locale_t locale
)
756 MSVCRT_size_t pos
= 0;
758 if(!dst
|| size
== 0)
759 return MSVCRT_EINVAL
;
763 return MSVCRT_EINVAL
;
768 if((locale
? locale
->mbcinfo
: get_mbcinfo())->ismbcodepage
)
770 BOOL is_lead
= FALSE
;
776 return MSVCRT_ERANGE
;
778 is_lead
= (!is_lead
&& _ismbblead(*src
));
783 if (is_lead
) /* if string ends with a lead, remove it */
794 return MSVCRT_ERANGE
;
807 return MSVCRT_ERANGE
;
813 /*********************************************************************
814 * _mbsnbcpy_s(MSVCRT.@)
816 int CDECL
_mbsnbcpy_s(unsigned char* dst
, MSVCRT_size_t size
, const unsigned char* src
, MSVCRT_size_t n
)
818 return _mbsnbcpy_s_l(dst
, size
, src
, n
, NULL
);
821 /*********************************************************************
822 * _mbscpy_s_l(MSVCRT.@)
824 int CDECL
_mbscpy_s_l(unsigned char *dst
, MSVCRT_size_t size
,
825 const unsigned char *src
, MSVCRT__locale_t locale
)
827 return _mbsnbcpy_s_l(dst
, size
, src
, -1, locale
);
830 /*********************************************************************
831 * _mbscpy_s(MSVCRT.@)
833 int CDECL
_mbscpy_s(unsigned char *dst
, MSVCRT_size_t size
, const unsigned char *src
)
835 return _mbscpy_s_l(dst
, size
, src
, NULL
);
838 /*********************************************************************
839 * _mbsnbcpy(MSVCRT.@)
841 * Like strncpy this function doesn't enforce the string to be
844 unsigned char* CDECL
_mbsnbcpy(unsigned char* dst
, const unsigned char* src
, MSVCRT_size_t n
)
846 unsigned char* ret
= dst
;
849 if(get_mbcinfo()->ismbcodepage
)
851 BOOL is_lead
= FALSE
;
854 is_lead
= (!is_lead
&& _ismbblead(*src
));
859 if (is_lead
) /* if string ends with a lead, remove it */
867 if (!(*dst
++ = *src
++)) break;
870 while (n
--) *dst
++ = 0;
874 /*********************************************************************
875 * _mbscmp_l(MSVCRT.@)
877 int CDECL
_mbscmp_l(const unsigned char* str
, const unsigned char* cmp
, MSVCRT__locale_t locale
)
879 MSVCRT_pthreadmbcinfo mbcinfo
;
881 if (!str
|| !cmp
) return INT_MAX
;
883 mbcinfo
= locale
? locale
->mbcinfo
: get_mbcinfo();
885 if(mbcinfo
->ismbcodepage
)
887 unsigned int strc
, cmpc
;
890 return *cmp
? -1 : 0;
893 strc
= _mbsnextc_l(str
, locale
);
894 cmpc
= _mbsnextc_l(cmp
, locale
);
896 return strc
< cmpc
? -1 : 1;
897 str
+=(strc
> 255) ? 2 : 1;
898 cmp
+=(strc
> 255) ? 2 : 1; /* equal, use same increment */
901 return u_strcmp(str
, cmp
); /* ASCII CP */
904 /*********************************************************************
907 int CDECL
_mbscmp(const unsigned char* str
, const unsigned char* cmp
, MSVCRT__locale_t locale
)
909 return _mbscmp_l(str
, cmp
, NULL
);
912 /*********************************************************************
913 * _mbsnbicoll_l(MSVCRT.@)
915 int CDECL
_mbsnbicoll_l(const unsigned char *str1
, const unsigned char *str2
, MSVCRT_size_t len
, MSVCRT__locale_t locale
)
917 MSVCRT_pthreadmbcinfo mbcinfo
;
920 mbcinfo
= get_mbcinfo();
922 mbcinfo
= locale
->mbcinfo
;
924 if(!mbcinfo
->ismbcodepage
)
925 return MSVCRT__strnicoll_l((const char*)str1
, (const char*)str2
, len
, locale
);
926 return CompareStringA(mbcinfo
->mblcid
, NORM_IGNORECASE
, (const char*)str1
, len
, (const char*)str2
, len
)-CSTR_EQUAL
;
929 /*********************************************************************
930 * _mbsicoll_l(MSVCRT.@)
932 int CDECL
_mbsicoll_l(const unsigned char *str1
, const unsigned char *str2
, MSVCRT__locale_t locale
)
934 return _mbsnbicoll_l(str1
, str2
, -1, locale
);
937 /*********************************************************************
938 * _mbsnbicoll(MSVCRT.@)
940 int CDECL
_mbsnbicoll(const unsigned char *str1
, const unsigned char *str2
, MSVCRT_size_t len
)
942 return _mbsnbicoll_l(str1
, str2
, len
, NULL
);
945 /*********************************************************************
946 * _mbsicoll(MSVCRT.@)
948 int CDECL
_mbsicoll(const unsigned char* str
, const unsigned char* cmp
)
950 #if _MSVCR_VER>=60 && _MSVCR_VER<=71
951 return CompareStringA(get_mbcinfo()->mblcid
, NORM_IGNORECASE
,
952 (const char*)str
, -1, (const char*)cmp
, -1)-CSTR_EQUAL
;
954 return _mbsnbicoll_l(str
, cmp
, -1, NULL
);
958 /*********************************************************************
959 * _mbsnbcoll_l(MSVCRT.@)
961 int CDECL
_mbsnbcoll_l(const unsigned char *str1
, const unsigned char *str2
, MSVCRT_size_t len
, MSVCRT__locale_t locale
)
963 MSVCRT_pthreadmbcinfo mbcinfo
;
966 mbcinfo
= get_mbcinfo();
968 mbcinfo
= locale
->mbcinfo
;
970 if(!mbcinfo
->ismbcodepage
)
971 return MSVCRT__strncoll_l((const char*)str1
, (const char*)str2
, len
, locale
);
972 return CompareStringA(mbcinfo
->mblcid
, 0, (const char*)str1
, len
, (const char*)str2
, len
)-CSTR_EQUAL
;
975 /*********************************************************************
976 * _mbscoll_l(MSVCRT.@)
978 int CDECL
_mbscoll_l(const unsigned char *str1
, const unsigned char *str2
, MSVCRT__locale_t locale
)
980 return _mbsnbcoll_l(str1
, str2
, -1, locale
);
983 /*********************************************************************
984 * _mbsnbcoll(MSVCRT.@)
986 int CDECL
_mbsnbcoll(const unsigned char *str1
, const unsigned char *str2
, MSVCRT_size_t len
)
988 return _mbsnbcoll_l(str1
, str2
, len
, NULL
);
991 /*********************************************************************
994 int CDECL
_mbscoll(const unsigned char* str
, const unsigned char* cmp
)
996 #if _MSVCR_VER>=60 && _MSVCR_VER<=71
997 return CompareStringA(get_mbcinfo()->mblcid
, 0,
998 (const char*)str
, -1, (const char*)cmp
, -1)-CSTR_EQUAL
;
1000 return _mbsnbcoll_l(str
, cmp
, -1, NULL
);
1004 /*********************************************************************
1005 * _mbsicmp(MSVCRT.@)
1007 int CDECL
_mbsicmp(const unsigned char* str
, const unsigned char* cmp
)
1009 if(get_mbcinfo()->ismbcodepage
)
1011 unsigned int strc
, cmpc
;
1014 return *cmp
? -1 : 0;
1017 strc
= _mbctolower(_mbsnextc(str
));
1018 cmpc
= _mbctolower(_mbsnextc(cmp
));
1020 return strc
< cmpc
? -1 : 1;
1021 str
+=(strc
> 255) ? 2 : 1;
1022 cmp
+=(strc
> 255) ? 2 : 1; /* equal, use same increment */
1025 return u_strcasecmp(str
, cmp
); /* ASCII CP */
1028 /*********************************************************************
1029 * _mbsncmp(MSVCRT.@)
1031 int CDECL
_mbsncmp(const unsigned char* str
, const unsigned char* cmp
, MSVCRT_size_t len
)
1036 if(get_mbcinfo()->ismbcodepage
)
1038 unsigned int strc
, cmpc
;
1043 return *cmp
? -1 : 0;
1046 strc
= _mbsnextc(str
);
1047 cmpc
= _mbsnextc(cmp
);
1049 return strc
< cmpc
? -1 : 1;
1050 inc
=(strc
> 255) ? 2 : 1; /* Equal, use same increment */
1054 return 0; /* Matched len chars */
1056 return u_strncmp(str
, cmp
, len
); /* ASCII CP */
1059 /*********************************************************************
1060 * _mbsnbcmp(MSVCRT.@)
1062 int CDECL
_mbsnbcmp(const unsigned char* str
, const unsigned char* cmp
, MSVCRT_size_t len
)
1066 if(get_mbcinfo()->ismbcodepage
)
1068 unsigned int strc
, cmpc
;
1073 return *cmp
? -1 : 0;
1076 if (_ismbblead(*str
))
1078 strc
=(len
>=2)?_mbsnextc(str
):0;
1086 if (_ismbblead(*cmp
))
1087 cmpc
=(len
>=2)?_mbsnextc(cmp
):0;
1091 return strc
< cmpc
? -1 : 1;
1096 return 0; /* Matched len chars */
1098 return u_strncmp(str
,cmp
,len
);
1101 /*********************************************************************
1102 * _mbsnicmp(MSVCRT.@)
1104 * Compare two multibyte strings case insensitively to 'len' characters.
1106 int CDECL
_mbsnicmp(const unsigned char* str
, const unsigned char* cmp
, MSVCRT_size_t len
)
1108 /* FIXME: No tolower() for mb strings yet */
1109 if(get_mbcinfo()->ismbcodepage
)
1111 unsigned int strc
, cmpc
;
1115 return *cmp
? -1 : 0;
1118 strc
= _mbctolower(_mbsnextc(str
));
1119 cmpc
= _mbctolower(_mbsnextc(cmp
));
1121 return strc
< cmpc
? -1 : 1;
1122 str
+=(strc
> 255) ? 2 : 1;
1123 cmp
+=(strc
> 255) ? 2 : 1; /* Equal, use same increment */
1125 return 0; /* Matched len chars */
1127 return u_strncasecmp(str
, cmp
, len
); /* ASCII CP */
1130 /*********************************************************************
1131 * _mbsnbicmp(MSVCRT.@)
1133 int CDECL
_mbsnbicmp(const unsigned char* str
, const unsigned char* cmp
, MSVCRT_size_t len
)
1137 if(get_mbcinfo()->ismbcodepage
)
1139 unsigned int strc
, cmpc
;
1144 return *cmp
? -1 : 0;
1147 if (_ismbblead(*str
))
1149 strc
=(len
>=2)?_mbsnextc(str
):0;
1157 if (_ismbblead(*cmp
))
1158 cmpc
=(len
>=2)?_mbsnextc(cmp
):0;
1161 strc
= _mbctolower(strc
);
1162 cmpc
= _mbctolower(cmpc
);
1164 return strc
< cmpc
? -1 : 1;
1169 return 0; /* Matched len bytes */
1171 return u_strncasecmp(str
,cmp
,len
);
1174 /*********************************************************************
1175 * _mbscat (MSVCRT.@)
1177 unsigned char * CDECL
_mbscat( unsigned char *dst
, const unsigned char *src
)
1179 strcat( (char *)dst
, (const char *)src
);
1183 /*********************************************************************
1184 * _mbscat_s_l (MSVCRT.@)
1186 int CDECL
_mbscat_s_l( unsigned char *dst
, MSVCRT_size_t size
,
1187 const unsigned char *src
, MSVCRT__locale_t locale
)
1192 if(!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
1193 if(!MSVCRT_CHECK_PMT(src
!= NULL
)) return MSVCRT_EINVAL
;
1195 for(i
=0; i
<size
; i
++)
1198 MSVCRT_INVALID_PMT("dst is not NULL-terminated", MSVCRT_EINVAL
);
1199 if(size
) dst
[0] = 0;
1200 return MSVCRT_EINVAL
;
1203 if(i
&& _ismbblead_l(dst
[i
-1], locale
)) {
1204 ret
= MSVCRT_EILSEQ
;
1208 for(j
=0; src
[j
] && i
+j
<size
; j
++)
1211 MSVCRT_INVALID_PMT("dst buffer is too small", MSVCRT_ERANGE
);
1213 return MSVCRT_ERANGE
;
1216 if(j
&& _ismbblead_l(src
[j
-1], locale
)) {
1217 ret
= MSVCRT_EILSEQ
;
1225 /*********************************************************************
1226 * _mbscat_s (MSVCRT.@)
1228 int CDECL
_mbscat_s( unsigned char *dst
, MSVCRT_size_t size
, const unsigned char *src
)
1230 return _mbscat_s_l(dst
, size
, src
, NULL
);
1233 /*********************************************************************
1234 * _mbscpy (MSVCRT.@)
1236 unsigned char* CDECL
_mbscpy( unsigned char *dst
, const unsigned char *src
)
1238 strcpy( (char *)dst
, (const char *)src
);
1242 /*********************************************************************
1243 * _mbsstr (MSVCRT.@)
1245 unsigned char * CDECL
_mbsstr(const unsigned char *haystack
, const unsigned char *needle
)
1247 return (unsigned char *)MSVCRT_strstr( (const char *)haystack
, (const char *)needle
);
1250 /*********************************************************************
1253 * Find a multibyte character in a multibyte string.
1255 unsigned char* CDECL
_mbschr(const unsigned char* s
, unsigned int x
)
1257 if(get_mbcinfo()->ismbcodepage
)
1264 return (unsigned char*)s
;
1267 s
+= c
> 255 ? 2 : 1;
1270 return u_strchr(s
, x
); /* ASCII CP */
1273 /*********************************************************************
1274 * _mbsrchr(MSVCRT.@)
1276 unsigned char* CDECL
_mbsrchr(const unsigned char* s
, unsigned int x
)
1278 if(get_mbcinfo()->ismbcodepage
)
1281 unsigned char* match
=NULL
;
1287 match
=(unsigned char*)s
;
1290 s
+=(c
> 255) ? 2 : 1;
1293 return u_strrchr(s
, x
);
1296 /*********************************************************************
1297 * _mbstok_s_l(MSVCRT.@)
1299 unsigned char* CDECL
_mbstok_s_l(unsigned char *str
, const unsigned char *delim
,
1300 unsigned char **ctx
, MSVCRT__locale_t locale
)
1302 MSVCRT_pthreadmbcinfo mbcinfo
;
1305 if(!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1306 if(!MSVCRT_CHECK_PMT(ctx
!= NULL
)) return NULL
;
1307 if(!MSVCRT_CHECK_PMT(str
|| *ctx
)) return NULL
;
1310 mbcinfo
= locale
->mbcinfo
;
1312 mbcinfo
= get_mbcinfo();
1314 if(!mbcinfo
->ismbcodepage
)
1315 return (unsigned char*)MSVCRT_strtok_s((char*)str
, (const char*)delim
, (char**)ctx
);
1320 while((c
=_mbsnextc(str
)) && _mbschr(delim
, c
))
1321 str
+= c
>255 ? 2 : 1;
1328 *ctx
= str
+ (c
>255 ? 2 : 1);
1329 while((c
=_mbsnextc(*ctx
)) && !_mbschr(delim
, c
))
1330 *ctx
+= c
>255 ? 2 : 1;
1341 /*********************************************************************
1342 * _mbstok_s(MSVCRT.@)
1344 unsigned char* CDECL
_mbstok_s(unsigned char *str
,
1345 const unsigned char *delim
, unsigned char **ctx
)
1347 return _mbstok_s_l(str
, delim
, ctx
, NULL
);
1350 /*********************************************************************
1351 * _mbstok_l(MSVCRT.@)
1353 unsigned char* CDECL
_mbstok_l(unsigned char *str
,
1354 const unsigned char *delim
, MSVCRT__locale_t locale
)
1356 return _mbstok_s_l(str
, delim
, &msvcrt_get_thread_data()->mbstok_next
, locale
);
1359 /*********************************************************************
1362 unsigned char* CDECL
_mbstok(unsigned char *str
, const unsigned char *delim
)
1364 thread_data_t
*data
= msvcrt_get_thread_data();
1367 if(!str
&& !data
->mbstok_next
)
1371 return _mbstok_s_l(str
, delim
, &data
->mbstok_next
, NULL
);
1374 /*********************************************************************
1375 * _mbbtombc(MSVCRT.@)
1377 unsigned int CDECL
_mbbtombc(unsigned int c
)
1379 if(get_mbcinfo()->mbcodepage
== 932)
1381 if(c
>= 0x20 && c
<= 0x7e) {
1382 if((c
>= 0x41 && c
<= 0x5a) || (c
>= 0x61 && c
<= 0x7a) || (c
>= 0x30 && c
<= 0x39))
1383 return mbbtombc_932
[c
- 0x20] | 0x8200;
1385 return mbbtombc_932
[c
- 0x20] | 0x8100;
1387 else if(c
>= 0xa1 && c
<= 0xdf) {
1388 if(c
>= 0xa6 && c
<= 0xdd && c
!= 0xb0)
1389 return mbbtombc_932
[c
- 0xa1 + 0x5f] | 0x8300;
1391 return mbbtombc_932
[c
- 0xa1 + 0x5f] | 0x8100;
1394 return c
; /* not Japanese or no MB char */
1397 /*********************************************************************
1398 * _ismbbkana_l(MSVCRT.@)
1400 int CDECL
_ismbbkana_l(unsigned int c
, MSVCRT__locale_t locale
)
1402 MSVCRT_pthreadmbcinfo mbcinfo
;
1405 mbcinfo
= locale
->mbcinfo
;
1407 mbcinfo
= get_mbcinfo();
1409 if(mbcinfo
->mbcodepage
== 932)
1411 /* Japanese/Katakana, CP 932 */
1412 return (c
>= 0xa1 && c
<= 0xdf);
1417 /*********************************************************************
1418 * _ismbbkana(MSVCRT.@)
1420 int CDECL
_ismbbkana(unsigned int c
)
1422 return _ismbbkana_l( c
, NULL
);
1425 /*********************************************************************
1426 * _ismbcdigit_l(MSVCRT.@)
1428 int CDECL
_ismbcdigit_l(unsigned int ch
, MSVCRT__locale_t locale
)
1430 return MSVCRT__iswdigit_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1433 /*********************************************************************
1434 * _ismbcdigit(MSVCRT.@)
1436 int CDECL
_ismbcdigit(unsigned int ch
)
1438 return _ismbcdigit_l( ch
, NULL
);
1441 /*********************************************************************
1442 * _ismbcgraph_l(MSVCRT.@)
1444 int CDECL
_ismbcgraph_l(unsigned int ch
, MSVCRT__locale_t locale
)
1446 return MSVCRT__iswgraph_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1449 /*********************************************************************
1450 * _ismbcgraph(MSVCRT.@)
1452 int CDECL
_ismbcgraph(unsigned int ch
)
1454 return _ismbcgraph_l( ch
, NULL
);
1457 /*********************************************************************
1458 * _ismbcalpha_l (MSVCRT.@)
1460 int CDECL
_ismbcalpha_l(unsigned int ch
, MSVCRT__locale_t locale
)
1462 return MSVCRT__iswalpha_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1465 /*********************************************************************
1466 * _ismbcalpha (MSVCRT.@)
1468 int CDECL
_ismbcalpha(unsigned int ch
)
1470 return _ismbcalpha_l( ch
, NULL
);
1473 /*********************************************************************
1474 * _ismbclower_l (MSVCRT.@)
1476 int CDECL
_ismbclower_l(unsigned int ch
, MSVCRT__locale_t locale
)
1478 return MSVCRT__iswlower_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1481 /*********************************************************************
1482 * _ismbclower (MSVCRT.@)
1484 int CDECL
_ismbclower(unsigned int ch
)
1486 return _ismbclower_l( ch
, NULL
);
1489 /*********************************************************************
1490 * _ismbcupper_l (MSVCRT.@)
1492 int CDECL
_ismbcupper_l(unsigned int ch
, MSVCRT__locale_t locale
)
1494 return MSVCRT__iswupper_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1497 /*********************************************************************
1498 * _ismbcupper (MSVCRT.@)
1500 int CDECL
_ismbcupper(unsigned int ch
)
1502 return _ismbcupper_l( ch
, NULL
);
1505 /*********************************************************************
1506 * _ismbcsymbol(MSVCRT.@)
1508 int CDECL
_ismbcsymbol(unsigned int ch
)
1510 MSVCRT_wchar_t wch
= msvcrt_mbc_to_wc( ch
);
1512 if (!GetStringTypeW(CT_CTYPE3
, &wch
, 1, &ctype
))
1514 WARN("GetStringTypeW failed on %x\n", ch
);
1517 return ((ctype
& C3_SYMBOL
) != 0);
1520 /*********************************************************************
1521 * _ismbcalnum_l (MSVCRT.@)
1523 int CDECL
_ismbcalnum_l(unsigned int ch
, MSVCRT__locale_t locale
)
1525 return MSVCRT__iswalnum_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1528 /*********************************************************************
1529 * _ismbcalnum (MSVCRT.@)
1531 int CDECL
_ismbcalnum(unsigned int ch
)
1533 return _ismbcalnum_l( ch
, NULL
);
1536 /*********************************************************************
1537 * _ismbcspace_l (MSVCRT.@)
1539 int CDECL
_ismbcspace_l(unsigned int ch
, MSVCRT__locale_t locale
)
1541 return MSVCRT__iswspace_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1544 /*********************************************************************
1545 * _ismbcspace (MSVCRT.@)
1547 int CDECL
_ismbcspace(unsigned int ch
)
1549 return _ismbcspace_l( ch
, NULL
);
1552 /*********************************************************************
1553 * _ismbcprint_l (MSVCRT.@)
1555 int CDECL
_ismbcprint_l(unsigned int ch
, MSVCRT__locale_t locale
)
1557 return MSVCRT__iswprint_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1560 /*********************************************************************
1561 * _ismbcprint (MSVCRT.@)
1563 int CDECL
_ismbcprint(unsigned int ch
)
1565 return _ismbcprint_l( ch
, NULL
);
1568 /*********************************************************************
1569 * _ismbcpunct_l (MSVCRT.@)
1571 int CDECL
_ismbcpunct_l(unsigned int ch
, MSVCRT__locale_t locale
)
1573 return MSVCRT__iswpunct_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1576 /*********************************************************************
1577 * _ismbcpunct(MSVCRT.@)
1579 int CDECL
_ismbcpunct(unsigned int ch
)
1581 return _ismbcpunct_l( ch
, NULL
);
1584 /*********************************************************************
1585 * _ismbchira(MSVCRT.@)
1587 int CDECL
_ismbchira(unsigned int c
)
1589 if(get_mbcinfo()->mbcodepage
== 932)
1591 /* Japanese/Hiragana, CP 932 */
1592 return (c
>= 0x829f && c
<= 0x82f1);
1597 /*********************************************************************
1598 * _ismbckata(MSVCRT.@)
1600 int CDECL
_ismbckata(unsigned int c
)
1602 if(get_mbcinfo()->mbcodepage
== 932)
1604 /* Japanese/Katakana, CP 932 */
1605 return (c
>= 0x8340 && c
<= 0x8396 && c
!= 0x837f);
1611 /*********************************************************************
1612 * _ismbblead_l(MSVCRT.@)
1614 int CDECL
_ismbblead_l(unsigned int c
, MSVCRT__locale_t locale
)
1616 MSVCRT_pthreadmbcinfo mbcinfo
;
1619 mbcinfo
= get_mbcinfo();
1621 mbcinfo
= locale
->mbcinfo
;
1623 return (mbcinfo
->mbctype
[(c
&0xff) + 1] & _M1
) != 0;
1626 /*********************************************************************
1627 * _ismbblead(MSVCRT.@)
1629 int CDECL
_ismbblead(unsigned int c
)
1631 return _ismbblead_l(c
, NULL
);
1634 /*********************************************************************
1635 * _ismbbtrail_l(MSVCRT.@)
1637 int CDECL
_ismbbtrail_l(unsigned int c
, MSVCRT__locale_t locale
)
1639 MSVCRT_pthreadmbcinfo mbcinfo
;
1642 mbcinfo
= get_mbcinfo();
1644 mbcinfo
= locale
->mbcinfo
;
1646 return (mbcinfo
->mbctype
[(c
&0xff) + 1] & _M2
) != 0;
1649 /*********************************************************************
1650 * _ismbbtrail(MSVCRT.@)
1652 int CDECL
_ismbbtrail(unsigned int c
)
1654 return _ismbbtrail_l(c
, NULL
);
1657 /*********************************************************************
1658 * _ismbclegal_l(MSVCRT.@)
1660 int CDECL
_ismbclegal_l(unsigned int c
, MSVCRT__locale_t locale
)
1662 return _ismbblead_l(HIBYTE(c
), locale
) && _ismbbtrail_l(LOBYTE(c
), locale
);
1665 /*********************************************************************
1666 * _ismbclegal(MSVCRT.@)
1668 int CDECL
_ismbclegal(unsigned int c
)
1670 return _ismbclegal_l(c
, NULL
);
1673 /*********************************************************************
1674 * _ismbslead(MSVCRT.@)
1676 int CDECL
_ismbslead(const unsigned char* start
, const unsigned char* str
)
1680 if(!get_mbcinfo()->ismbcodepage
)
1683 /* Lead bytes can also be trail bytes so we need to analyse the string
1685 while (start
<= str
)
1689 lead
= !lead
&& _ismbblead(*start
);
1693 return lead
? -1 : 0;
1696 /*********************************************************************
1697 * _ismbstrail(MSVCRT.@)
1699 int CDECL
_ismbstrail(const unsigned char* start
, const unsigned char* str
)
1701 /* Note: this function doesn't check _ismbbtrail */
1702 if ((str
> start
) && _ismbslead(start
, str
-1))
1708 /*********************************************************************
1709 * _mbbtype_l(MSVCRT.@)
1711 int CDECL
_mbbtype_l(unsigned char c
, int type
, MSVCRT__locale_t locale
)
1714 return _ismbbtrail_l(c
, locale
) ? _MBC_TRAIL
: _MBC_ILLEGAL
;
1716 return _ismbblead_l(c
, locale
) ? _MBC_LEAD
1717 : MSVCRT__isprint_l(c
, locale
) ? _MBC_SINGLE
: _MBC_ILLEGAL
;
1720 /*********************************************************************
1721 * _mbbtype(MSVCRT.@)
1723 int CDECL
_mbbtype(unsigned char c
, int type
)
1725 return _mbbtype_l(c
, type
, NULL
);
1728 /*********************************************************************
1729 * _mbsbtype (MSVCRT.@)
1731 int CDECL
_mbsbtype(const unsigned char *str
, MSVCRT_size_t count
)
1734 const unsigned char *end
= str
+ count
;
1736 /* Lead bytes can also be trail bytes so we need to analyse the string.
1737 * Also we must return _MBC_ILLEGAL for chars past the end of the string
1739 while (str
< end
) /* Note: we skip the last byte - will check after the loop */
1742 return _MBC_ILLEGAL
;
1743 lead
= get_mbcinfo()->ismbcodepage
&& !lead
&& _ismbblead(*str
);
1748 if (_ismbbtrail(*str
))
1751 return _MBC_ILLEGAL
;
1753 if (_ismbblead(*str
))
1759 /*********************************************************************
1762 unsigned char* CDECL
_mbsset(unsigned char* str
, unsigned int c
)
1764 unsigned char* ret
= str
;
1766 if(!get_mbcinfo()->ismbcodepage
|| c
< 256)
1767 return u__strset(str
, c
); /* ASCII CP or SB char */
1769 c
&= 0xffff; /* Strip high bits */
1771 while(str
[0] && str
[1])
1777 str
[0] = '\0'; /* FIXME: OK to shorten? */
1782 /*********************************************************************
1783 * _mbsnbset(MSVCRT.@)
1785 unsigned char* CDECL
_mbsnbset(unsigned char *str
, unsigned int c
, MSVCRT_size_t len
)
1787 unsigned char *ret
= str
;
1792 if(!get_mbcinfo()->ismbcodepage
|| c
< 256)
1793 return u__strnset(str
, c
, len
); /* ASCII CP or SB char */
1795 c
&= 0xffff; /* Strip high bits */
1797 while(str
[0] && str
[1] && (len
> 1))
1805 /* as per msdn pad with a blank character */
1812 /*********************************************************************
1813 * _mbsnset(MSVCRT.@)
1815 unsigned char* CDECL
_mbsnset(unsigned char* str
, unsigned int c
, MSVCRT_size_t len
)
1817 unsigned char *ret
= str
;
1822 if(!get_mbcinfo()->ismbcodepage
|| c
< 256)
1823 return u__strnset(str
, c
, len
); /* ASCII CP or SB char */
1825 c
&= 0xffff; /* Strip high bits */
1827 while(str
[0] && str
[1] && len
--)
1833 str
[0] = '\0'; /* FIXME: OK to shorten? */
1838 /*********************************************************************
1839 * _mbsnccnt(MSVCRT.@)
1840 * 'c' is for 'character'.
1842 MSVCRT_size_t CDECL
_mbsnccnt(const unsigned char* str
, MSVCRT_size_t len
)
1845 if(get_mbcinfo()->ismbcodepage
)
1848 while(*str
&& len
-- > 0)
1850 if(_ismbblead(*str
))
1863 return min(ret
, len
); /* ASCII CP */
1866 /*********************************************************************
1867 * _mbsnbcnt(MSVCRT.@)
1868 * 'b' is for byte count.
1870 MSVCRT_size_t CDECL
_mbsnbcnt(const unsigned char* str
, MSVCRT_size_t len
)
1873 if(get_mbcinfo()->ismbcodepage
)
1875 const unsigned char* xstr
= str
;
1876 while(*xstr
&& len
-- > 0)
1878 if (_ismbblead(*xstr
++))
1884 return min(ret
, len
); /* ASCII CP */
1887 /*********************************************************************
1888 * _mbsnbcat(MSVCRT.@)
1890 unsigned char* CDECL
_mbsnbcat(unsigned char* dst
, const unsigned char* src
, MSVCRT_size_t len
)
1892 if(get_mbcinfo()->ismbcodepage
)
1894 unsigned char *res
= dst
;
1896 if (_ismbblead(*dst
++)) {
1900 /* as per msdn overwrite the lead byte in front of '\0' */
1906 while (*src
&& len
--) *dst
++ = *src
++;
1910 return u_strncat(dst
, src
, len
); /* ASCII CP */
1913 int CDECL
_mbsnbcat_s(unsigned char *dst
, MSVCRT_size_t size
, const unsigned char *src
, MSVCRT_size_t len
)
1915 unsigned char *ptr
= dst
;
1918 if (!dst
&& !size
&& !src
&& !len
)
1921 if (!dst
|| !size
|| !src
)
1926 *MSVCRT__errno() = MSVCRT_EINVAL
;
1927 return MSVCRT_EINVAL
;
1930 /* Find the null terminator of the destination buffer. */
1931 while (size
&& *ptr
)
1937 *MSVCRT__errno() = MSVCRT_EINVAL
;
1938 return MSVCRT_EINVAL
;
1941 /* If necessary, check that the character preceding the null terminator is
1942 * a lead byte and move the pointer back by one for later overwrite. */
1943 if (ptr
!= dst
&& get_mbcinfo()->ismbcodepage
&& _ismbblead(*(ptr
- 1)))
1946 for (i
= 0; *src
&& i
< len
; i
++)
1954 *MSVCRT__errno() = MSVCRT_ERANGE
;
1955 return MSVCRT_ERANGE
;
1963 /*********************************************************************
1964 * _mbsncat(MSVCRT.@)
1966 unsigned char* CDECL
_mbsncat(unsigned char* dst
, const unsigned char* src
, MSVCRT_size_t len
)
1968 if(get_mbcinfo()->ismbcodepage
)
1970 unsigned char *res
= dst
;
1973 if (_ismbblead(*dst
++))
1976 while (*src
&& len
--)
1979 if(_ismbblead(*src
++))
1985 return u_strncat(dst
, src
, len
); /* ASCII CP */
1989 /*********************************************************************
1992 unsigned char* CDECL
_mbslwr(unsigned char* s
)
1994 unsigned char *ret
= s
;
1997 if (get_mbcinfo()->ismbcodepage
)
2002 c
= _mbctolower(_mbsnextc(s
));
2003 /* Note that I assume that the size of the character is unchanged */
2012 else for ( ; *s
; s
++) *s
= MSVCRT__tolower_l(*s
, NULL
);
2017 /*********************************************************************
2018 * _mbslwr_s(MSVCRT.@)
2020 int CDECL
_mbslwr_s(unsigned char* s
, MSVCRT_size_t len
)
2026 else if (!s
|| !len
)
2028 *MSVCRT__errno() = MSVCRT_EINVAL
;
2029 return MSVCRT_EINVAL
;
2031 if (get_mbcinfo()->ismbcodepage
)
2034 for ( ; *s
&& len
> 0; len
--)
2036 c
= _mbctolower(_mbsnextc(s
));
2037 /* Note that I assume that the size of the character is unchanged */
2046 else for ( ; *s
&& len
> 0; s
++, len
--) *s
= MSVCRT__tolower_l(*s
, NULL
);
2050 *MSVCRT__errno() = MSVCRT_EINVAL
;
2051 return MSVCRT_EINVAL
;
2057 /*********************************************************************
2060 unsigned char* CDECL
_mbsupr(unsigned char* s
)
2062 unsigned char *ret
= s
;
2065 if (get_mbcinfo()->ismbcodepage
)
2070 c
= _mbctoupper(_mbsnextc(s
));
2071 /* Note that I assume that the size of the character is unchanged */
2080 else for ( ; *s
; s
++) *s
= MSVCRT__toupper_l(*s
, NULL
);
2085 /*********************************************************************
2086 * _mbsupr_s(MSVCRT.@)
2088 int CDECL
_mbsupr_s(unsigned char* s
, MSVCRT_size_t len
)
2094 else if (!s
|| !len
)
2096 *MSVCRT__errno() = MSVCRT_EINVAL
;
2097 return MSVCRT_EINVAL
;
2099 if (get_mbcinfo()->ismbcodepage
)
2102 for ( ; *s
&& len
> 0; len
--)
2104 c
= _mbctoupper(_mbsnextc(s
));
2105 /* Note that I assume that the size of the character is unchanged */
2114 else for ( ; *s
&& len
> 0; s
++, len
--) *s
= MSVCRT__toupper_l(*s
, NULL
);
2118 *MSVCRT__errno() = MSVCRT_EINVAL
;
2119 return MSVCRT_EINVAL
;
2124 /*********************************************************************
2125 * _mbsspn_l (MSVCRT.@)
2127 MSVCRT_size_t CDECL
_mbsspn_l(const unsigned char* string
,
2128 const unsigned char* set
, MSVCRT__locale_t locale
)
2130 const unsigned char *p
, *q
;
2132 for (p
= string
; *p
; p
++)
2134 for (q
= set
; *q
; q
++)
2136 if (_ismbblead_l(*q
, locale
))
2138 /* duplicate a bug in native implementation */
2141 if (p
[0] == q
[0] && p
[1] == q
[1])
2150 if (p
[0] == q
[0]) break;
2158 /*********************************************************************
2159 * _mbsspn (MSVCRT.@)
2161 MSVCRT_size_t CDECL
_mbsspn(const unsigned char* string
, const unsigned char* set
)
2163 return _mbsspn_l(string
, set
, NULL
);
2166 /*********************************************************************
2167 * _mbsspnp (MSVCRT.@)
2169 unsigned char* CDECL
_mbsspnp(const unsigned char* string
, const unsigned char* set
)
2171 string
+= _mbsspn( string
, set
);
2172 return *string
? (unsigned char*)string
: NULL
;
2175 /*********************************************************************
2176 * _mbscspn_l (MSVCRT.@)
2178 MSVCRT_size_t CDECL
_mbscspn_l(const unsigned char* str
,
2179 const unsigned char* cmp
, MSVCRT__locale_t locale
)
2181 const unsigned char *p
, *q
;
2183 for (p
= str
; *p
; p
++)
2185 for (q
= cmp
; *q
; q
++)
2187 if (_ismbblead_l(*q
, locale
))
2189 /* duplicate a bug in native implementation */
2190 if (!q
[1]) return 0;
2192 if (p
[0] == q
[0] && p
[1] == q
[1])
2196 else if (p
[0] == q
[0])
2203 /*********************************************************************
2204 * _mbscspn (MSVCRT.@)
2206 MSVCRT_size_t CDECL
_mbscspn(const unsigned char* str
, const unsigned char* cmp
)
2208 return _mbscspn_l(str
, cmp
, NULL
);
2211 /*********************************************************************
2212 * _mbsrev (MSVCRT.@)
2214 unsigned char* CDECL
_mbsrev(unsigned char* str
)
2216 int i
, len
= _mbslen(str
);
2217 unsigned char *p
, *temp
=MSVCRT_malloc(len
*2);
2222 /* unpack multibyte string to temp buffer */
2224 for(i
=0; i
<len
; i
++)
2238 /* repack it in the reverse order */
2240 for(i
=len
-1; i
>=0; i
--)
2242 if(_ismbblead(temp
[i
*2]))
2258 /*********************************************************************
2259 * _mbspbrk (MSVCRT.@)
2261 unsigned char* CDECL
_mbspbrk(const unsigned char* str
, const unsigned char* accept
)
2263 const unsigned char* p
;
2267 for(p
= accept
; *p
; p
+= (_ismbblead(*p
)?2:1) )
2270 if( !_ismbblead(*p
) || ( *(p
+1) == *(str
+1) ) )
2271 return (unsigned char*)str
;
2273 str
+= (_ismbblead(*str
)?2:1);
2280 * Functions depending on locale codepage
2283 /*********************************************************************
2286 * Unlike most of the multibyte string functions this function uses
2287 * the locale codepage, not the codepage set by _setmbcp
2289 int CDECL
MSVCRT_mblen(const char* str
, MSVCRT_size_t size
)
2291 if (str
&& *str
&& size
)
2293 if(get_locinfo()->mb_cur_max
== 1)
2294 return 1; /* ASCII CP */
2296 return !MSVCRT_isleadbyte((unsigned char)*str
) ? 1 : (size
>1 ? 2 : -1);
2301 /*********************************************************************
2304 MSVCRT_size_t CDECL
MSVCRT_mbrlen(const char *str
, MSVCRT_size_t len
, MSVCRT_mbstate_t
*state
)
2306 MSVCRT_mbstate_t s
= (state
? *state
: 0);
2309 if(!len
|| !str
|| !*str
)
2312 if(get_locinfo()->mb_cur_max
== 1) {
2314 }else if(!s
&& MSVCRT_isleadbyte((unsigned char)*str
)) {
2316 s
= (unsigned char)*str
;
2333 /*********************************************************************
2334 * _mbstrlen_l(MSVCRT.@)
2336 MSVCRT_size_t CDECL
_mbstrlen_l(const char* str
, MSVCRT__locale_t locale
)
2338 MSVCRT_pthreadlocinfo locinfo
;
2341 locinfo
= get_locinfo();
2343 locinfo
= locale
->locinfo
;
2345 if(locinfo
->mb_cur_max
> 1) {
2347 len
= MultiByteToWideChar(locinfo
->lc_codepage
, MB_ERR_INVALID_CHARS
,
2350 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2359 /*********************************************************************
2360 * _mbstrlen(MSVCRT.@)
2362 MSVCRT_size_t CDECL
_mbstrlen(const char* str
)
2364 return _mbstrlen_l(str
, NULL
);
2367 /*********************************************************************
2368 * _mbtowc_l(MSVCRT.@)
2370 int CDECL
MSVCRT_mbtowc_l(MSVCRT_wchar_t
*dst
, const char* str
, MSVCRT_size_t n
, MSVCRT__locale_t locale
)
2372 MSVCRT_pthreadlocinfo locinfo
;
2373 MSVCRT_wchar_t tmpdst
= '\0';
2376 locinfo
= get_locinfo();
2378 locinfo
= locale
->locinfo
;
2388 if(!locinfo
->lc_codepage
) {
2389 if(dst
) *dst
= (unsigned char)*str
;
2392 if(n
>=2 && MSVCRT__isleadbyte_l((unsigned char)*str
, locale
)) {
2393 if(!MultiByteToWideChar(locinfo
->lc_codepage
, 0, str
, 2, &tmpdst
, 1))
2395 if(dst
) *dst
= tmpdst
;
2398 if(!MultiByteToWideChar(locinfo
->lc_codepage
, 0, str
, 1, &tmpdst
, 1))
2400 if(dst
) *dst
= tmpdst
;
2404 /*********************************************************************
2407 int CDECL
MSVCRT_mbtowc(MSVCRT_wchar_t
*dst
, const char* str
, MSVCRT_size_t n
)
2409 return MSVCRT_mbtowc_l(dst
, str
, n
, NULL
);
2412 /*********************************************************************
2415 MSVCRT_size_t CDECL
MSVCRT_mbrtowc(MSVCRT_wchar_t
*dst
, const char *str
,
2416 MSVCRT_size_t n
, MSVCRT_mbstate_t
*state
)
2418 MSVCRT_pthreadlocinfo locinfo
= get_locinfo();
2419 MSVCRT_mbstate_t s
= (state
? *state
: 0);
2426 if(!n
|| !str
|| !*str
)
2429 if(locinfo
->mb_cur_max
== 1) {
2430 tmpstr
[len
++] = *str
;
2431 }else if(!s
&& MSVCRT_isleadbyte((unsigned char)*str
)) {
2433 s
= (unsigned char)*str
;
2441 tmpstr
[len
++] = *str
;
2450 if(!MultiByteToWideChar(locinfo
->lc_codepage
, 0, tmpstr
, len
, dst
, dst
? 1 : 0))
2459 /*********************************************************************
2460 * _mbstowcs_l(MSVCRT.@)
2462 MSVCRT_size_t CDECL
MSVCRT__mbstowcs_l(MSVCRT_wchar_t
*wcstr
, const char *mbstr
,
2463 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
2465 MSVCRT_pthreadlocinfo locinfo
;
2466 MSVCRT_size_t i
, size
;
2469 *MSVCRT__errno() = MSVCRT_EINVAL
;
2474 locinfo
= get_locinfo();
2476 locinfo
= locale
->locinfo
;
2478 if(!locinfo
->lc_codepage
) {
2480 return strlen(mbstr
);
2482 for(i
=0; i
<count
; i
++) {
2483 wcstr
[i
] = (unsigned char)mbstr
[i
];
2484 if(!wcstr
[i
]) break;
2489 /* Ignore count parameter */
2491 size
= MultiByteToWideChar(locinfo
->lc_codepage
,
2492 MB_ERR_INVALID_CHARS
, mbstr
, -1, NULL
, 0);
2494 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2500 for(i
=0, size
=0; i
<count
; i
++) {
2501 if(mbstr
[size
] == '\0')
2504 size
+= (MSVCRT__isleadbyte_l((unsigned char)mbstr
[size
], locale
) ? 2 : 1);
2508 size
= MultiByteToWideChar(locinfo
->lc_codepage
,
2509 MB_ERR_INVALID_CHARS
, mbstr
, size
, wcstr
, count
);
2511 if(count
) wcstr
[0] = '\0';
2512 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2523 /*********************************************************************
2524 * mbstowcs(MSVCRT.@)
2526 MSVCRT_size_t CDECL
MSVCRT_mbstowcs(MSVCRT_wchar_t
*wcstr
,
2527 const char *mbstr
, MSVCRT_size_t count
)
2529 return MSVCRT__mbstowcs_l(wcstr
, mbstr
, count
, NULL
);
2532 /*********************************************************************
2533 * _mbstowcs_s_l(MSVCRT.@)
2535 int CDECL
MSVCRT__mbstowcs_s_l(MSVCRT_size_t
*ret
, MSVCRT_wchar_t
*wcstr
,
2536 MSVCRT_size_t size
, const char *mbstr
,
2537 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
2542 if(!wcstr
&& !size
) {
2543 conv
= MSVCRT__mbstowcs_l(NULL
, mbstr
, 0, locale
);
2549 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return MSVCRT_EINVAL
;
2550 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) {
2551 if(size
) wcstr
[0] = '\0';
2552 return MSVCRT_EINVAL
;
2555 if(count
==MSVCRT__TRUNCATE
|| size
<count
)
2560 conv
= MSVCRT__mbstowcs_l(wcstr
, mbstr
, conv
, locale
);
2562 wcstr
[conv
++] = '\0';
2563 else if(conv
==size
&& count
==MSVCRT__TRUNCATE
&& wcstr
[conv
-1]!='\0') {
2564 wcstr
[conv
-1] = '\0';
2565 err
= MSVCRT_STRUNCATE
;
2566 }else if(conv
==size
&& wcstr
[conv
-1]!='\0') {
2567 MSVCRT_INVALID_PMT("wcstr[size] is too small", MSVCRT_ERANGE
);
2570 return MSVCRT_ERANGE
;
2578 /*********************************************************************
2579 * mbstowcs_s(MSVCRT.@)
2581 int CDECL
MSVCRT__mbstowcs_s(MSVCRT_size_t
*ret
, MSVCRT_wchar_t
*wcstr
,
2582 MSVCRT_size_t size
, const char *mbstr
, MSVCRT_size_t count
)
2584 return MSVCRT__mbstowcs_s_l(ret
, wcstr
, size
, mbstr
, count
, NULL
);
2587 /*********************************************************************
2588 * mbsrtowcs(MSVCRT.@)
2590 MSVCRT_size_t CDECL
MSVCRT_mbsrtowcs(MSVCRT_wchar_t
*wcstr
,
2591 const char **pmbstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*state
)
2593 MSVCRT_mbstate_t s
= (state
? *state
: 0);
2594 MSVCRT_wchar_t tmpdst
;
2595 MSVCRT_size_t ret
= 0;
2598 if(!MSVCRT_CHECK_PMT(pmbstr
!= NULL
))
2602 while(!wcstr
|| count
>ret
) {
2603 int ch_len
= MSVCRT_mbrtowc(&tmpdst
, p
, 2, &s
);
2605 wcstr
[ret
] = tmpdst
;
2609 }else if(ch_len
== 0) {
2610 if(wcstr
) *pmbstr
= NULL
;
2618 if(wcstr
) *pmbstr
= p
;
2622 /*********************************************************************
2623 * mbsrtowcs_s(MSVCRT.@)
2625 int CDECL
MSVCRT_mbsrtowcs_s(MSVCRT_size_t
*ret
, MSVCRT_wchar_t
*wcstr
, MSVCRT_size_t len
,
2626 const char **mbstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*state
)
2630 if(!ret
) ret
= &tmp
;
2631 if(!MSVCRT_CHECK_PMT(!!wcstr
== !!len
)) {
2633 return MSVCRT_EINVAL
;
2636 *ret
= MSVCRT_mbsrtowcs(wcstr
, mbstr
, count
>len
? len
: count
, state
);
2638 if(wcstr
) *wcstr
= 0;
2639 return *MSVCRT__errno();
2643 /* no place for terminating '\0' */
2644 if(wcstr
) *wcstr
= 0;
2647 if(wcstr
) wcstr
[(*ret
)-1] = 0;
2651 /*********************************************************************
2652 * _mbctohira (MSVCRT.@)
2654 * Converts a sjis katakana character to hiragana.
2656 unsigned int CDECL
_mbctohira(unsigned int c
)
2658 if(_ismbckata(c
) && c
<= 0x8393)
2659 return (c
- 0x8340 - (c
>= 0x837f ? 1 : 0)) + 0x829f;
2663 /*********************************************************************
2664 * _mbctokata (MSVCRT.@)
2666 * Converts a sjis hiragana character to katakana.
2668 unsigned int CDECL
_mbctokata(unsigned int c
)
2671 return (c
- 0x829f) + 0x8340 + (c
>= 0x82de ? 1 : 0);
2675 /*********************************************************************
2676 * _ismbcl0_l (MSVCRT.@)
2678 int CDECL
_ismbcl0_l(unsigned int c
, MSVCRT__locale_t locale
)
2680 MSVCRT_pthreadmbcinfo mbcinfo
;
2683 mbcinfo
= get_mbcinfo();
2685 mbcinfo
= locale
->mbcinfo
;
2687 if(mbcinfo
->mbcodepage
== 932)
2690 return _ismbclegal_l(c
, locale
) && c
>= 0x8140 && c
<= 0x889e;
2696 /*********************************************************************
2697 * _ismbcl0 (MSVCRT.@)
2699 int CDECL
_ismbcl0(unsigned int c
)
2701 return _ismbcl0_l(c
, NULL
);
2704 /*********************************************************************
2705 * _ismbcl1_l (MSVCRT.@)
2707 int CDECL
_ismbcl1_l(unsigned int c
, MSVCRT__locale_t locale
)
2709 MSVCRT_pthreadmbcinfo mbcinfo
;
2712 mbcinfo
= get_mbcinfo();
2714 mbcinfo
= locale
->mbcinfo
;
2716 if(mbcinfo
->mbcodepage
== 932)
2719 return _ismbclegal_l(c
, locale
) && c
>= 0x889f && c
<= 0x9872;
2725 /*********************************************************************
2726 * _ismbcl1 (MSVCRT.@)
2728 int CDECL
_ismbcl1(unsigned int c
)
2730 return _ismbcl1_l(c
, NULL
);
2733 /*********************************************************************
2734 * _ismbcl2_l (MSVCRT.@)
2736 int CDECL
_ismbcl2_l(unsigned int c
, MSVCRT__locale_t locale
)
2738 MSVCRT_pthreadmbcinfo mbcinfo
;
2741 mbcinfo
= get_mbcinfo();
2743 mbcinfo
= locale
->mbcinfo
;
2745 if(mbcinfo
->mbcodepage
== 932)
2748 return _ismbclegal_l(c
, locale
) && c
>= 0x989f && c
<= 0xeaa4;
2754 /*********************************************************************
2755 * _ismbcl2 (MSVCRT.@)
2757 int CDECL
_ismbcl2(unsigned int c
)
2759 return _ismbcl2_l(c
, NULL
);