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.
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
38 unsigned char MSVCRT_mbctype
[257] = { 0 };
40 /* It seems that the data about valid trail bytes is not available from kernel32
41 * so we have to store is here. The format is the same as for lead bytes in CPINFO */
42 struct cp_extra_info_t
45 BYTE TrailBytes
[MAX_LEADBYTES
];
48 static struct cp_extra_info_t g_cpextrainfo
[] =
50 {932, {0x40, 0x7e, 0x80, 0xfc, 0, 0}},
51 {936, {0x40, 0xfe, 0, 0}},
52 {949, {0x41, 0xfe, 0, 0}},
53 {950, {0x40, 0x7e, 0xa1, 0xfe, 0, 0}},
54 {1361, {0x31, 0x7e, 0x81, 0xfe, 0, 0}},
55 {20932, {1, 255, 0, 0}}, /* seems to give different results on different systems */
56 {0, {1, 255, 0, 0}} /* match all with FIXME */
59 /* Maps cp932 single byte character to multi byte character */
60 static const unsigned char mbbtombc_932
[] = {
61 0x40,0x49,0x68,0x94,0x90,0x93,0x95,0x66,0x69,0x6a,0x96,0x7b,0x43,0x7c,0x44,0x5e,
62 0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x46,0x47,0x83,0x81,0x84,0x48,
63 0x97,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,
64 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x76,
65 0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x51,0x65,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
66 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x50,
67 0x42,0x75,0x76,0x41,0x45,0x92,0x40,0x42,0x44,0x46,0x48,0x83,0x85,0x87,0x62,
68 0x5b,0x41,0x43,0x45,0x47,0x49,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,
69 0x5e,0x60,0x63,0x65,0x67,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x71,0x74,0x77,0x7a,0x7d,
70 0x7e,0x80,0x81,0x82,0x84,0x86,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8f,0x93,0x4a,0x4b };
72 /* Maps multibyte cp932 punctuation marks to single byte equivalents */
73 static const unsigned char mbctombb_932_punct
[] = {
74 0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e,
75 0x7e,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x00,0x00,0x2f,0x00,
76 0x00,0x00,0x7c,0x00,0x00,0x60,0x27,0x00,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,0x7b,
77 0x7d,0x00,0x00,0x00,0x00,0xa2,0xa3,0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,0x00,
78 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5c,
79 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40};
81 /* Maps multibyte cp932 hiragana/katakana to single-byte equivalents */
82 static const unsigned char mbctombb_932_kana
[] = {
83 0xa7,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8,0xb8,
84 0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0,0xc0,
85 0xc1,0xc1,0xaf,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xca,
86 0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0,0xd1,
87 0xd2,0xd3,0xac,0xd4,0xad,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xb2,
88 0xb4,0xa6,0xdd,0xb3,0xb6,0xb9};
90 static wchar_t msvcrt_mbc_to_wc_l(unsigned int ch
, _locale_t locale
)
92 pthreadmbcinfo mbcinfo
;
98 mbcinfo
= locale
->mbcinfo
;
100 mbcinfo
= get_mbcinfo();
106 mbch
[0] = (ch
>> 8) & 0xff;
110 if (!MultiByteToWideChar(mbcinfo
->mbcodepage
, 0, mbch
, n_chars
, &chW
, 1))
112 WARN("MultiByteToWideChar failed on %x\n", ch
);
118 static inline size_t u_strlen( const unsigned char *str
)
120 return strlen( (const char*) str
);
123 static inline unsigned char* u_strncat( unsigned char* dst
, const unsigned char* src
, size_t len
)
125 return (unsigned char*)strncat( (char*)dst
, (const char*)src
, len
);
128 static inline int u_strcmp( const unsigned char *s1
, const unsigned char *s2
)
130 return strcmp( (const char*)s1
, (const char*)s2
);
133 static inline int u_strcasecmp( const unsigned char *s1
, const unsigned char *s2
)
135 return _stricmp( (const char*)s1
, (const char*)s2
);
138 static inline int u_strncmp( const unsigned char *s1
, const unsigned char *s2
, size_t len
)
140 return strncmp( (const char*)s1
, (const char*)s2
, len
);
143 static inline int u_strncasecmp( const unsigned char *s1
, const unsigned char *s2
, size_t len
)
145 return _strnicmp( (const char*)s1
, (const char*)s2
, len
);
148 static inline unsigned char *u_strchr( const unsigned char *s
, unsigned char x
)
150 return (unsigned char*) strchr( (const char*)s
, x
);
153 static inline unsigned char *u_strrchr( const unsigned char *s
, unsigned char x
)
155 return (unsigned char*) strrchr( (const char*)s
, x
);
158 static inline unsigned char *u__strset( unsigned char *s
, unsigned char c
)
160 return (unsigned char*) _strset( (char*)s
, c
);
163 static inline unsigned char *u__strnset( unsigned char *s
, unsigned char c
, size_t len
)
165 return (unsigned char*) _strnset( (char*)s
, c
, len
);
168 /*********************************************************************
169 * __p__mbctype (MSVCRT.@)
171 unsigned char* CDECL
__p__mbctype(void)
173 return get_mbcinfo()->mbctype
;
176 /*********************************************************************
177 * __p___mb_cur_max(MSVCRT.@)
179 int* CDECL
__p___mb_cur_max(void)
181 return &get_locinfo()->mb_cur_max
;
184 /*********************************************************************
185 * ___mb_cur_max_func(MSVCRT.@)
187 int CDECL
___mb_cur_max_func(void)
189 return get_locinfo()->mb_cur_max
;
193 /*********************************************************************
194 * ___mb_cur_max_l_func (MSVCR80.@)
196 int CDECL
___mb_cur_max_l_func(_locale_t locale
)
198 pthreadlocinfo locinfo
;
201 locinfo
= get_locinfo();
203 locinfo
= locale
->locinfo
;
205 return locinfo
->mb_cur_max
;
209 threadmbcinfo
* create_mbcinfo(int cp
, LCID lcid
, threadmbcinfo
*old_mbcinfo
)
211 threadmbcinfo
*mbcinfo
;
217 WCHAR bufW
[256], lowW
[256], upW
[256];
218 int charcount
, maxchar
;
222 if(old_mbcinfo
&& cp
==old_mbcinfo
->mbcodepage
223 && (lcid
==-1 || lcid
==old_mbcinfo
->mblcid
)) {
224 InterlockedIncrement(&old_mbcinfo
->refcount
);
228 mbcinfo
= malloc(sizeof(threadmbcinfo
));
231 mbcinfo
->refcount
= 1;
242 newcp
= get_locinfo()->lc_codepage
;
245 /* fall through (C locale) */
247 newcp
= 20127; /* ASCII */
255 WCHAR wbuf
[LOCALE_NAME_MAX_LENGTH
];
256 sprintf(bufA
, ".%d", newcp
);
257 mbcinfo
->mblcid
= locale_to_sname(bufA
, NULL
, NULL
, wbuf
) ? LocaleNameToLCID(wbuf
, LOCALE_ALLOW_NEUTRAL_NAMES
) : -1;
259 mbcinfo
->mblcid
= lcid
;
262 if(mbcinfo
->mblcid
== -1)
264 WARN("Can't assign LCID to codepage (%d)\n", mbcinfo
->mblcid
);
268 if (!GetCPInfo(newcp
, &cpi
))
270 WARN("Codepage %d not found\n", newcp
);
275 /* setup the _mbctype */
276 memset(mbcinfo
->mbctype
, 0, sizeof(unsigned char[257]));
277 memset(mbcinfo
->mbcasemap
, 0, sizeof(unsigned char[256]));
279 bytes
= cpi
.LeadByte
;
280 while (bytes
[0] || bytes
[1])
282 for (i
= bytes
[0]; i
<= bytes
[1]; i
++)
283 mbcinfo
->mbctype
[i
+ 1] |= _M1
;
287 if (cpi
.MaxCharSize
== 2)
289 /* trail bytes not available through kernel32 but stored in a structure in msvcrt */
290 struct cp_extra_info_t
*cpextra
= g_cpextrainfo
;
292 mbcinfo
->ismbcodepage
= 1;
295 if (cpextra
->cp
== 0 || cpextra
->cp
== newcp
)
297 if (cpextra
->cp
== 0)
298 FIXME("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp
);
300 bytes
= cpextra
->TrailBytes
;
301 while (bytes
[0] || bytes
[1])
303 for (i
= bytes
[0]; i
<= bytes
[1]; i
++)
304 mbcinfo
->mbctype
[i
+ 1] |= _M2
;
313 mbcinfo
->ismbcodepage
= 0;
315 maxchar
= (newcp
== CP_UTF8
) ? 128 : 256;
317 /* we can't use GetStringTypeA directly because we don't have a locale - only a code page
320 for (i
= 0; i
< maxchar
; i
++)
321 if (!(mbcinfo
->mbctype
[i
+ 1] & _M1
))
322 bufA
[charcount
++] = i
;
324 ret
= MultiByteToWideChar(newcp
, 0, bufA
, charcount
, bufW
, charcount
);
325 if (ret
!= charcount
)
327 ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%ld\n",
328 newcp
, ret
, charcount
, GetLastError());
331 GetStringTypeW(CT_CTYPE1
, bufW
, charcount
, chartypes
);
332 LCMapStringW(mbcinfo
->mblcid
, LCMAP_LOWERCASE
, bufW
, charcount
, lowW
, charcount
);
333 LCMapStringW(mbcinfo
->mblcid
, LCMAP_UPPERCASE
, bufW
, charcount
, upW
, charcount
);
336 for (i
= 0; i
< maxchar
; i
++)
337 if (!(mbcinfo
->mbctype
[i
+ 1] & _M1
))
339 if (chartypes
[charcount
] & C1_UPPER
)
341 mbcinfo
->mbctype
[i
+ 1] |= _SBUP
;
342 bufW
[charcount
] = lowW
[charcount
];
344 else if (chartypes
[charcount
] & C1_LOWER
)
346 mbcinfo
->mbctype
[i
+ 1] |= _SBLOW
;
347 bufW
[charcount
] = upW
[charcount
];
352 ret
= WideCharToMultiByte(newcp
, 0, bufW
, charcount
, bufA
, charcount
, NULL
, NULL
);
353 if (ret
!= charcount
)
355 ERR("WideCharToMultiByte failed for cp %d, ret=%d (exp %d), error=%ld\n",
356 newcp
, ret
, charcount
, GetLastError());
360 for (i
= 0; i
< maxchar
; i
++)
362 if(!(mbcinfo
->mbctype
[i
+ 1] & _M1
))
364 if(mbcinfo
->mbctype
[i
+ 1] & (_SBUP
| _SBLOW
))
365 mbcinfo
->mbcasemap
[i
] = bufA
[charcount
];
370 if (newcp
== 932) /* CP932 only - set _MP and _MS */
372 /* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
373 * and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes
374 * it hard. As this is set only for codepage 932 we hardcode it what gives
375 * also faster execution.
377 for (i
= 161; i
<= 165; i
++)
378 mbcinfo
->mbctype
[i
+ 1] |= _MP
;
379 for (i
= 166; i
<= 223; i
++)
380 mbcinfo
->mbctype
[i
+ 1] |= _MS
;
383 mbcinfo
->mbcodepage
= newcp
;
387 /*********************************************************************
388 * _setmbcp (MSVCRT.@)
390 int CDECL
_setmbcp(int cp
)
392 thread_data_t
*data
= msvcrt_get_thread_data();
393 threadmbcinfo
*mbcinfo
;
395 mbcinfo
= create_mbcinfo(cp
, -1, get_mbcinfo());
402 if(data
->locale_flags
& LOCALE_THREAD
)
404 if(data
->locale_flags
& LOCALE_FREE
)
405 free_mbcinfo(data
->mbcinfo
);
406 data
->mbcinfo
= mbcinfo
;
411 free_mbcinfo(MSVCRT_locale
->mbcinfo
);
412 MSVCRT_locale
->mbcinfo
= mbcinfo
;
413 memcpy(MSVCRT_mbctype
, MSVCRT_locale
->mbcinfo
->mbctype
, sizeof(MSVCRT_mbctype
));
414 _unlock(_MB_CP_LOCK
);
419 /*********************************************************************
420 * _getmbcp (MSVCRT.@)
422 int CDECL
_getmbcp(void)
424 return get_mbcinfo()->mbcodepage
;
427 /*********************************************************************
428 * _mbsnextc_l(MSVCRT.@)
430 unsigned int CDECL
_mbsnextc_l(const unsigned char* str
, _locale_t locale
)
432 if(_ismbblead_l(*str
, locale
))
433 return *str
<< 8 | str
[1];
437 /*********************************************************************
438 * _mbsnextc(MSVCRT.@)
440 unsigned int CDECL
_mbsnextc(const unsigned char* str
)
442 return _mbsnextc_l(str
, NULL
);
445 /*********************************************************************
446 * _mbctolower_l(MSVCRT.@)
448 unsigned int CDECL
_mbctolower_l(unsigned int c
, _locale_t locale
)
450 unsigned char str
[2], ret
[2];
451 pthreadmbcinfo mbcinfo
;
454 mbcinfo
= get_mbcinfo();
456 mbcinfo
= locale
->mbcinfo
;
460 if (!_ismbblead_l((c
>> 8) & 0xff, locale
))
465 switch(__crtLCMapStringA(mbcinfo
->mblcid
, LCMAP_LOWERCASE
,
466 (char*)str
, 2, (char*)ret
, 2, mbcinfo
->mbcodepage
, 0))
473 return ret
[1] + (ret
[0] << 8);
477 return mbcinfo
->mbctype
[c
+ 1] & _SBUP
? mbcinfo
->mbcasemap
[c
] : c
;
480 /*********************************************************************
481 * _mbctolower(MSVCRT.@)
483 unsigned int CDECL
_mbctolower(unsigned int c
)
485 return _mbctolower_l(c
, NULL
);
488 /*********************************************************************
489 * _mbctoupper_l(MSVCRT.@)
491 unsigned int CDECL
_mbctoupper_l(unsigned int c
, _locale_t locale
)
493 unsigned char str
[2], ret
[2];
494 pthreadmbcinfo mbcinfo
;
497 mbcinfo
= get_mbcinfo();
499 mbcinfo
= locale
->mbcinfo
;
503 if (!_ismbblead_l((c
>> 8) & 0xff, locale
))
508 switch(__crtLCMapStringA(mbcinfo
->mblcid
, LCMAP_UPPERCASE
,
509 (char*)str
, 2, (char*)ret
, 2, mbcinfo
->mbcodepage
, 0))
516 return ret
[1] + (ret
[0] << 8);
520 return mbcinfo
->mbctype
[c
+ 1] & _SBLOW
? mbcinfo
->mbcasemap
[c
] : c
;
523 /*********************************************************************
524 * _mbctoupper(MSVCRT.@)
526 unsigned int CDECL
_mbctoupper(unsigned int c
)
528 return _mbctoupper_l(c
, NULL
);
531 /*********************************************************************
532 * _mbctombb_l (MSVCRT.@)
534 unsigned int CDECL
_mbctombb_l(unsigned int c
, _locale_t locale
)
536 pthreadmbcinfo mbcinfo
;
540 mbcinfo
= locale
->mbcinfo
;
542 mbcinfo
= get_mbcinfo();
544 if(mbcinfo
->mbcodepage
== 932)
546 if(c
>= 0x829f && c
<= 0x82f1) /* Hiragana */
547 return mbctombb_932_kana
[c
- 0x829f];
548 if(c
>= 0x8340 && c
<= 0x8396 && c
!= 0x837f) /* Katakana */
549 return mbctombb_932_kana
[c
- 0x8340 - (c
>= 0x837f ? 1 : 0)];
550 if(c
>= 0x8140 && c
<= 0x8197) /* Punctuation */
552 value
= mbctombb_932_punct
[c
- 0x8140];
553 return value
? value
: c
;
555 if((c
>= 0x824f && c
<= 0x8258) || /* Fullwidth digits */
556 (c
>= 0x8260 && c
<= 0x8279)) /* Fullwidth capitals letters */
558 if(c
>= 0x8281 && c
<= 0x829a) /* Fullwidth small letters */
560 /* all other cases return c */
565 /*********************************************************************
566 * _mbctombb (MSVCRT.@)
568 unsigned int CDECL
_mbctombb(unsigned int c
)
570 return _mbctombb_l(c
, NULL
);
573 /*********************************************************************
574 * _mbcjistojms_l(MSVCRT.@)
576 * Converts a jis character to sjis.
577 * Based on description from
578 * http://www.slayers.ne.jp/~oouchi/code/jistosjis.html
580 unsigned int CDECL
_mbcjistojms_l(unsigned int c
, _locale_t locale
)
582 pthreadmbcinfo mbcinfo
;
585 mbcinfo
= locale
->mbcinfo
;
587 mbcinfo
= get_mbcinfo();
589 /* Conversion takes place only when codepage is 932.
590 In all other cases, c is returned unchanged */
591 if(mbcinfo
->mbcodepage
== 932)
593 if(HIBYTE(c
) >= 0x21 && HIBYTE(c
) <= 0x7e &&
594 LOBYTE(c
) >= 0x21 && LOBYTE(c
) <= 0x7e)
601 if(LOBYTE(c
) >= 0x7F)
604 c
= (((HIBYTE(c
) - 0x21)/2 + 0x81) << 8) | LOBYTE(c
);
610 return 0; /* Codepage is 932, but c can't be converted */
616 /*********************************************************************
617 * _mbcjistojms(MSVCRT.@)
619 unsigned int CDECL
_mbcjistojms(unsigned int c
)
621 return _mbcjistojms_l(c
, NULL
);
624 /*********************************************************************
625 * _mbcjmstojis_l(MSVCRT.@)
627 * Converts a sjis character to jis.
629 unsigned int CDECL
_mbcjmstojis_l(unsigned int c
, _locale_t locale
)
631 pthreadmbcinfo mbcinfo
;
634 mbcinfo
= locale
->mbcinfo
;
636 mbcinfo
= get_mbcinfo();
638 /* Conversion takes place only when codepage is 932.
639 In all other cases, c is returned unchanged */
640 if(mbcinfo
->mbcodepage
== 932)
642 if(_ismbclegal_l(c
, locale
) && HIBYTE(c
) < 0xf0)
644 if(HIBYTE(c
) >= 0xe0)
647 c
= (((HIBYTE(c
) - 0x81)*2 + 0x21) << 8) | LOBYTE(c
);
658 return 0; /* Codepage is 932, but c can't be converted */
664 /*********************************************************************
665 * _mbcjmstojis(MSVCRT.@)
667 unsigned int CDECL
_mbcjmstojis(unsigned int c
)
669 return _mbcjmstojis_l(c
, NULL
);
672 /*********************************************************************
675 unsigned char* CDECL
_mbsdec(const unsigned char* start
, const unsigned char* cur
)
680 if(get_mbcinfo()->ismbcodepage
)
681 return (unsigned char *)(_ismbstrail(start
,cur
-1) ? cur
- 2 : cur
-1);
683 return (unsigned char *)cur
- 1; /* ASCII CP or SB char */
686 /*********************************************************************
687 * _mbclen_l(MSVCRT.@)
689 size_t CDECL
_mbclen_l(const unsigned char* str
, _locale_t locale
)
691 return _ismbblead_l(*str
, locale
) && str
[1] ? 2 : 1;
694 /*********************************************************************
697 size_t CDECL
_mbclen(const unsigned char* str
)
699 return _mbclen_l(str
, NULL
);
702 /*********************************************************************
703 * _mbsinc_l(MSVCRT.@)
705 unsigned char* CDECL
_mbsinc_l(const unsigned char* str
, _locale_t locale
)
707 return (unsigned char *)(str
+ _mbclen_l(str
, locale
));
710 /*********************************************************************
713 unsigned char* CDECL
_mbsinc(const unsigned char* str
)
715 return _mbsinc_l(str
, NULL
);
718 /*********************************************************************
721 unsigned char* CDECL
_mbsninc(const unsigned char* str
, size_t num
)
726 while (num
> 0 && *str
)
728 if (_ismbblead(*str
))
738 return (unsigned char*)str
;
741 /*********************************************************************
742 * _mbsnlen_l(MSVCRT.@)
744 size_t CDECL
_mbsnlen_l(const unsigned char *str
,
745 size_t maxsize
, _locale_t locale
)
747 pthreadmbcinfo mbcinfo
;
748 size_t i
= 0, len
= 0;
751 mbcinfo
= get_mbcinfo();
753 mbcinfo
= locale
->mbcinfo
;
755 if(!mbcinfo
->ismbcodepage
)
756 return strnlen((const char*)str
, maxsize
);
758 while(i
<maxsize
&& str
[i
])
760 if (_ismbblead_l(str
[i
], locale
))
763 if (!str
[i
]) /* count only full chars */
769 return i
< maxsize
? len
: maxsize
;
772 /*********************************************************************
775 size_t CDECL
_mbslen(const unsigned char* str
)
777 return _mbsnlen_l(str
, -1, NULL
);
780 /*********************************************************************
781 * _mbslen_l(MSVCRT.@)
783 size_t CDECL
_mbslen_l(const unsigned char* str
, _locale_t locale
)
785 return _mbsnlen_l(str
, -1, locale
);
788 /*********************************************************************
791 size_t CDECL
_mbsnlen(const unsigned char* str
, size_t maxsize
)
793 return _mbsnlen_l(str
, maxsize
, NULL
);
796 /*********************************************************************
797 * _mbccpy_s_l(MSVCRT.@)
799 int CDECL
_mbccpy_s_l(unsigned char* dest
, size_t maxsize
,
800 int *copied
, const unsigned char* src
, _locale_t locale
)
802 if(copied
) *copied
= 0;
803 if(!MSVCRT_CHECK_PMT(dest
!= NULL
&& maxsize
>= 1)) return EINVAL
;
805 if(!MSVCRT_CHECK_PMT(src
!= NULL
)) return EINVAL
;
807 if(_ismbblead_l(*src
, locale
)) {
809 if(copied
) *copied
= 1;
815 MSVCRT_INVALID_PMT("dst buffer is too small", ERANGE
);
821 if(copied
) *copied
= 2;
824 if(copied
) *copied
= 1;
830 /*********************************************************************
833 void CDECL
_mbccpy(unsigned char* dest
, const unsigned char* src
)
835 _mbccpy_s_l(dest
, 2, NULL
, src
, NULL
);
838 /*********************************************************************
839 * _mbccpy_l(MSVCRT.@)
841 void CDECL
_mbccpy_l(unsigned char* dest
, const unsigned char* src
,
844 _mbccpy_s_l(dest
, 2, NULL
, src
, locale
);
847 /*********************************************************************
848 * _mbccpy_s(MSVCRT.@)
850 int CDECL
_mbccpy_s(unsigned char* dest
, size_t maxsize
,
851 int *copied
, const unsigned char* src
)
853 return _mbccpy_s_l(dest
, maxsize
, copied
, src
, NULL
);
856 /*********************************************************************
859 * The parameter n is the number or characters to copy, not the size of
860 * the buffer. Use _mbsnbcpy for a function analogical to strncpy
862 unsigned char* CDECL
_mbsncpy(unsigned char* dst
, const unsigned char* src
, size_t n
)
864 unsigned char* ret
= dst
;
867 if (get_mbcinfo()->ismbcodepage
)
872 if (_ismbblead(*src
))
892 if (!(*dst
++ = *src
++)) break;
895 while (n
--) *dst
++ = 0;
899 /*********************************************************************
900 * _mbsnbcpy_s_l(MSVCRT.@)
902 * Unlike _mbsnbcpy this function does not pad the rest of the dest
905 int CDECL
_mbsnbcpy_s_l(unsigned char* dst
, size_t size
,
906 const unsigned char* src
, size_t n
, _locale_t locale
)
910 if(!dst
|| size
== 0)
920 if((locale
? locale
->mbcinfo
: get_mbcinfo())->ismbcodepage
)
922 BOOL is_lead
= FALSE
;
930 is_lead
= (!is_lead
&& _ismbblead(*src
));
935 if (is_lead
) /* if string ends with a lead, remove it */
965 /*********************************************************************
966 * _mbsnbcpy_s(MSVCRT.@)
968 int CDECL
_mbsnbcpy_s(unsigned char* dst
, size_t size
, const unsigned char* src
, size_t n
)
970 return _mbsnbcpy_s_l(dst
, size
, src
, n
, NULL
);
973 /*********************************************************************
974 * _mbscpy_s_l(MSVCRT.@)
976 int CDECL
_mbscpy_s_l(unsigned char *dst
, size_t size
,
977 const unsigned char *src
, _locale_t locale
)
979 return _mbsnbcpy_s_l(dst
, size
, src
, -1, locale
);
982 /*********************************************************************
983 * _mbscpy_s(MSVCRT.@)
985 int CDECL
_mbscpy_s(unsigned char *dst
, size_t size
, const unsigned char *src
)
987 return _mbscpy_s_l(dst
, size
, src
, NULL
);
990 /*********************************************************************
991 * _mbsnbcpy(MSVCRT.@)
993 * Like strncpy this function doesn't enforce the string to be
996 unsigned char* CDECL
_mbsnbcpy(unsigned char* dst
, const unsigned char* src
, size_t n
)
998 unsigned char* ret
= dst
;
1001 if(get_mbcinfo()->ismbcodepage
)
1003 BOOL is_lead
= FALSE
;
1006 is_lead
= (!is_lead
&& _ismbblead(*src
));
1011 if (is_lead
) /* if string ends with a lead, remove it */
1019 if (!(*dst
++ = *src
++)) break;
1022 while (n
--) *dst
++ = 0;
1026 /*********************************************************************
1027 * _mbscmp_l(MSVCRT.@)
1029 int CDECL
_mbscmp_l(const unsigned char* str
, const unsigned char* cmp
, _locale_t locale
)
1031 pthreadmbcinfo mbcinfo
;
1033 if (!MSVCRT_CHECK_PMT(str
&& cmp
))
1034 return _NLSCMPERROR
;
1036 mbcinfo
= locale
? locale
->mbcinfo
: get_mbcinfo();
1038 if(mbcinfo
->ismbcodepage
)
1040 unsigned int strc
, cmpc
;
1043 return *cmp
? -1 : 0;
1046 strc
= _mbsnextc_l(str
, locale
);
1047 cmpc
= _mbsnextc_l(cmp
, locale
);
1049 return strc
< cmpc
? -1 : 1;
1050 str
+=(strc
> 255) ? 2 : 1;
1051 cmp
+=(strc
> 255) ? 2 : 1; /* equal, use same increment */
1054 return u_strcmp(str
, cmp
); /* ASCII CP */
1057 /*********************************************************************
1060 int CDECL
_mbscmp(const unsigned char* str
, const unsigned char* cmp
)
1062 return _mbscmp_l(str
, cmp
, NULL
);
1065 /*********************************************************************
1066 * _mbsnbicoll_l(MSVCRT.@)
1068 int CDECL
_mbsnbicoll_l(const unsigned char *str1
, const unsigned char *str2
, size_t len
, _locale_t locale
)
1070 pthreadmbcinfo mbcinfo
;
1073 mbcinfo
= get_mbcinfo();
1075 mbcinfo
= locale
->mbcinfo
;
1077 if(!mbcinfo
->ismbcodepage
)
1078 return _strnicoll_l((const char*)str1
, (const char*)str2
, len
, locale
);
1079 return CompareStringA(mbcinfo
->mblcid
, NORM_IGNORECASE
, (const char*)str1
, len
, (const char*)str2
, len
)-CSTR_EQUAL
;
1082 /*********************************************************************
1083 * _mbsicoll_l(MSVCRT.@)
1085 int CDECL
_mbsicoll_l(const unsigned char *str1
, const unsigned char *str2
, _locale_t locale
)
1087 return _mbsnbicoll_l(str1
, str2
, -1, locale
);
1090 /*********************************************************************
1091 * _mbsnbicoll(MSVCRT.@)
1093 int CDECL
_mbsnbicoll(const unsigned char *str1
, const unsigned char *str2
, size_t len
)
1095 return _mbsnbicoll_l(str1
, str2
, len
, NULL
);
1098 /*********************************************************************
1099 * _mbsicoll(MSVCRT.@)
1101 int CDECL
_mbsicoll(const unsigned char* str
, const unsigned char* cmp
)
1103 #if _MSVCR_VER>=60 && _MSVCR_VER<=71
1104 return CompareStringA(get_mbcinfo()->mblcid
, NORM_IGNORECASE
,
1105 (const char*)str
, -1, (const char*)cmp
, -1)-CSTR_EQUAL
;
1107 return _mbsnbicoll_l(str
, cmp
, -1, NULL
);
1111 /*********************************************************************
1112 * _mbsnbcoll_l(MSVCRT.@)
1114 int CDECL
_mbsnbcoll_l(const unsigned char *str1
, const unsigned char *str2
, size_t len
, _locale_t locale
)
1116 pthreadmbcinfo mbcinfo
;
1119 mbcinfo
= get_mbcinfo();
1121 mbcinfo
= locale
->mbcinfo
;
1123 if(!mbcinfo
->ismbcodepage
)
1124 return _strncoll_l((const char*)str1
, (const char*)str2
, len
, locale
);
1125 return CompareStringA(mbcinfo
->mblcid
, 0, (const char*)str1
, len
, (const char*)str2
, len
)-CSTR_EQUAL
;
1128 /*********************************************************************
1129 * _mbscoll_l(MSVCRT.@)
1131 int CDECL
_mbscoll_l(const unsigned char *str1
, const unsigned char *str2
, _locale_t locale
)
1133 return _mbsnbcoll_l(str1
, str2
, -1, locale
);
1136 /*********************************************************************
1137 * _mbsnbcoll(MSVCRT.@)
1139 int CDECL
_mbsnbcoll(const unsigned char *str1
, const unsigned char *str2
, size_t len
)
1141 return _mbsnbcoll_l(str1
, str2
, len
, NULL
);
1144 /*********************************************************************
1145 * _mbscoll(MSVCRT.@)
1147 int CDECL
_mbscoll(const unsigned char* str
, const unsigned char* cmp
)
1149 #if _MSVCR_VER>=60 && _MSVCR_VER<=71
1150 return CompareStringA(get_mbcinfo()->mblcid
, 0,
1151 (const char*)str
, -1, (const char*)cmp
, -1)-CSTR_EQUAL
;
1153 return _mbsnbcoll_l(str
, cmp
, -1, NULL
);
1157 /*********************************************************************
1158 * _mbsicmp_l(MSVCRT.@)
1160 int CDECL
_mbsicmp_l(const unsigned char* str
, const unsigned char* cmp
, _locale_t locale
)
1162 pthreadmbcinfo mbcinfo
;
1164 if(!MSVCRT_CHECK_PMT(str
&& cmp
))
1165 return _NLSCMPERROR
;
1168 mbcinfo
= get_mbcinfo();
1170 mbcinfo
= locale
->mbcinfo
;
1171 if(mbcinfo
->ismbcodepage
)
1173 unsigned int strc
, cmpc
;
1176 return *cmp
? -1 : 0;
1179 strc
= _mbctolower_l(_mbsnextc_l(str
, locale
), locale
);
1180 cmpc
= _mbctolower_l(_mbsnextc_l(cmp
, locale
), locale
);
1182 return strc
< cmpc
? -1 : 1;
1183 str
+=(strc
> 255) ? 2 : 1;
1184 cmp
+=(strc
> 255) ? 2 : 1; /* equal, use same increment */
1187 return u_strcasecmp(str
, cmp
); /* ASCII CP */
1190 /*********************************************************************
1191 * _mbsicmp(MSVCRT.@)
1193 int CDECL
_mbsicmp(const unsigned char* str
, const unsigned char* cmp
)
1195 return _mbsicmp_l(str
, cmp
, NULL
);
1198 /*********************************************************************
1199 * _mbsncmp(MSVCRT.@)
1201 int CDECL
_mbsncmp(const unsigned char* str
, const unsigned char* cmp
, size_t len
)
1206 if(get_mbcinfo()->ismbcodepage
)
1208 unsigned int strc
, cmpc
;
1213 return *cmp
? -1 : 0;
1216 strc
= _mbsnextc(str
);
1217 cmpc
= _mbsnextc(cmp
);
1219 return strc
< cmpc
? -1 : 1;
1220 inc
=(strc
> 255) ? 2 : 1; /* Equal, use same increment */
1224 return 0; /* Matched len chars */
1226 return u_strncmp(str
, cmp
, len
); /* ASCII CP */
1229 /*********************************************************************
1230 * _mbsnbcmp(MSVCRT.@)
1232 int CDECL
_mbsnbcmp(const unsigned char* str
, const unsigned char* cmp
, size_t len
)
1236 if(get_mbcinfo()->ismbcodepage
)
1238 unsigned int strc
, cmpc
;
1243 return *cmp
? -1 : 0;
1246 if (_ismbblead(*str
))
1248 strc
=(len
>=2)?_mbsnextc(str
):0;
1256 if (_ismbblead(*cmp
))
1257 cmpc
=(len
>=2)?_mbsnextc(cmp
):0;
1261 return strc
< cmpc
? -1 : 1;
1266 return 0; /* Matched len chars */
1268 return u_strncmp(str
,cmp
,len
);
1271 /*********************************************************************
1272 * _mbsnicmp(MSVCRT.@)
1274 * Compare two multibyte strings case insensitively to 'len' characters.
1276 int CDECL
_mbsnicmp(const unsigned char* str
, const unsigned char* cmp
, size_t len
)
1278 /* FIXME: No tolower() for mb strings yet */
1279 if(get_mbcinfo()->ismbcodepage
)
1281 unsigned int strc
, cmpc
;
1285 return *cmp
? -1 : 0;
1288 strc
= _mbctolower(_mbsnextc(str
));
1289 cmpc
= _mbctolower(_mbsnextc(cmp
));
1291 return strc
< cmpc
? -1 : 1;
1292 str
+=(strc
> 255) ? 2 : 1;
1293 cmp
+=(strc
> 255) ? 2 : 1; /* Equal, use same increment */
1295 return 0; /* Matched len chars */
1297 return u_strncasecmp(str
, cmp
, len
); /* ASCII CP */
1300 /*********************************************************************
1301 * _mbsnbicmp(MSVCRT.@)
1303 int CDECL
_mbsnbicmp(const unsigned char* str
, const unsigned char* cmp
, size_t len
)
1307 if(get_mbcinfo()->ismbcodepage
)
1309 unsigned int strc
, cmpc
;
1314 return *cmp
? -1 : 0;
1317 if (_ismbblead(*str
))
1319 strc
=(len
>=2)?_mbsnextc(str
):0;
1327 if (_ismbblead(*cmp
))
1328 cmpc
=(len
>=2)?_mbsnextc(cmp
):0;
1331 strc
= _mbctolower(strc
);
1332 cmpc
= _mbctolower(cmpc
);
1334 return strc
< cmpc
? -1 : 1;
1339 return 0; /* Matched len bytes */
1341 return u_strncasecmp(str
,cmp
,len
);
1344 /*********************************************************************
1345 * _mbscat (MSVCRT.@)
1347 unsigned char * CDECL
_mbscat( unsigned char *dst
, const unsigned char *src
)
1349 strcat( (char *)dst
, (const char *)src
);
1353 /*********************************************************************
1354 * _mbscat_s_l (MSVCRT.@)
1356 int CDECL
_mbscat_s_l( unsigned char *dst
, size_t size
,
1357 const unsigned char *src
, _locale_t locale
)
1362 if(!MSVCRT_CHECK_PMT(dst
!= NULL
)) return EINVAL
;
1363 if(!MSVCRT_CHECK_PMT(src
!= NULL
)) return EINVAL
;
1365 for(i
=0; i
<size
; i
++)
1368 MSVCRT_INVALID_PMT("dst is not NULL-terminated", EINVAL
);
1369 if(size
) dst
[0] = 0;
1373 if(i
&& _ismbblead_l(dst
[i
-1], locale
)) {
1378 for(j
=0; src
[j
] && i
+j
<size
; j
++)
1381 MSVCRT_INVALID_PMT("dst buffer is too small", ERANGE
);
1386 if(j
&& _ismbblead_l(src
[j
-1], locale
)) {
1395 /*********************************************************************
1396 * _mbscat_s (MSVCRT.@)
1398 int CDECL
_mbscat_s( unsigned char *dst
, size_t size
, const unsigned char *src
)
1400 return _mbscat_s_l(dst
, size
, src
, NULL
);
1403 /*********************************************************************
1404 * _mbscpy (MSVCRT.@)
1406 unsigned char* CDECL
_mbscpy( unsigned char *dst
, const unsigned char *src
)
1408 strcpy( (char *)dst
, (const char *)src
);
1412 /*********************************************************************
1413 * _mbsstr (MSVCRT.@)
1415 unsigned char * CDECL
_mbsstr(const unsigned char *haystack
, const unsigned char *needle
)
1417 return (unsigned char *)strstr( (const char *)haystack
, (const char *)needle
);
1420 /*********************************************************************
1421 * _mbschr_l(MSVCRT.@)
1423 unsigned char* CDECL
_mbschr_l(const unsigned char* s
, unsigned int x
, _locale_t locale
)
1425 pthreadmbcinfo mbcinfo
;
1427 if(!MSVCRT_CHECK_PMT(s
))
1431 mbcinfo
= locale
->mbcinfo
;
1433 mbcinfo
= get_mbcinfo();
1434 if(mbcinfo
->ismbcodepage
)
1439 c
= _mbsnextc_l(s
, locale
);
1441 return (unsigned char*)s
;
1444 s
+= c
> 255 ? 2 : 1;
1447 return u_strchr(s
, x
); /* ASCII CP */
1450 /*********************************************************************
1453 unsigned char* CDECL
_mbschr(const unsigned char* s
, unsigned int x
)
1455 return _mbschr_l(s
, x
, NULL
);
1458 /*********************************************************************
1459 * _mbsrchr(MSVCRT.@)
1461 unsigned char* CDECL
_mbsrchr(const unsigned char* s
, unsigned int x
)
1463 if(get_mbcinfo()->ismbcodepage
)
1466 unsigned char* match
=NULL
;
1472 match
=(unsigned char*)s
;
1475 s
+=(c
> 255) ? 2 : 1;
1478 return u_strrchr(s
, x
);
1481 /*********************************************************************
1482 * _mbstok_s_l(MSVCRT.@)
1484 unsigned char* CDECL
_mbstok_s_l(unsigned char *str
, const unsigned char *delim
,
1485 unsigned char **ctx
, _locale_t locale
)
1487 pthreadmbcinfo mbcinfo
;
1490 if(!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1491 if(!MSVCRT_CHECK_PMT(ctx
!= NULL
)) return NULL
;
1492 if(!MSVCRT_CHECK_PMT(str
|| *ctx
)) return NULL
;
1495 mbcinfo
= locale
->mbcinfo
;
1497 mbcinfo
= get_mbcinfo();
1499 if(!mbcinfo
->ismbcodepage
)
1500 return (unsigned char*)strtok_s((char*)str
, (const char*)delim
, (char**)ctx
);
1505 while((c
=_mbsnextc(str
)) && _mbschr(delim
, c
))
1506 str
+= c
>255 ? 2 : 1;
1513 *ctx
= str
+ (c
>255 ? 2 : 1);
1514 while((c
=_mbsnextc(*ctx
)) && !_mbschr(delim
, c
))
1515 *ctx
+= c
>255 ? 2 : 1;
1526 /*********************************************************************
1527 * _mbstok_s(MSVCRT.@)
1529 unsigned char* CDECL
_mbstok_s(unsigned char *str
,
1530 const unsigned char *delim
, unsigned char **ctx
)
1532 return _mbstok_s_l(str
, delim
, ctx
, NULL
);
1535 /*********************************************************************
1536 * _mbstok_l(MSVCRT.@)
1538 unsigned char* CDECL
_mbstok_l(unsigned char *str
,
1539 const unsigned char *delim
, _locale_t locale
)
1541 return _mbstok_s_l(str
, delim
, &msvcrt_get_thread_data()->mbstok_next
, locale
);
1544 /*********************************************************************
1547 unsigned char* CDECL
_mbstok(unsigned char *str
, const unsigned char *delim
)
1549 thread_data_t
*data
= msvcrt_get_thread_data();
1552 if(!str
&& !data
->mbstok_next
)
1556 return _mbstok_s_l(str
, delim
, &data
->mbstok_next
, NULL
);
1559 /*********************************************************************
1560 * _mbbtombc_l(MSVCRT.@)
1562 unsigned int CDECL
_mbbtombc_l(unsigned int c
, _locale_t locale
)
1564 pthreadmbcinfo mbcinfo
;
1567 mbcinfo
= locale
->mbcinfo
;
1569 mbcinfo
= get_mbcinfo();
1571 if(mbcinfo
->mbcodepage
== 932)
1573 if(c
>= 0x20 && c
<= 0x7e) {
1574 if((c
>= 0x41 && c
<= 0x5a) || (c
>= 0x61 && c
<= 0x7a) || (c
>= 0x30 && c
<= 0x39))
1575 return mbbtombc_932
[c
- 0x20] | 0x8200;
1577 return mbbtombc_932
[c
- 0x20] | 0x8100;
1579 else if(c
>= 0xa1 && c
<= 0xdf) {
1580 if(c
>= 0xa6 && c
<= 0xdd && c
!= 0xb0)
1581 return mbbtombc_932
[c
- 0xa1 + 0x5f] | 0x8300;
1583 return mbbtombc_932
[c
- 0xa1 + 0x5f] | 0x8100;
1586 return c
; /* not Japanese or no MB char */
1589 /*********************************************************************
1590 * _mbbtombc(MSVCRT.@)
1592 unsigned int CDECL
_mbbtombc(unsigned int c
)
1594 return _mbbtombc_l(c
, NULL
);
1597 /*********************************************************************
1598 * _ismbbkana_l(MSVCRT.@)
1600 int CDECL
_ismbbkana_l(unsigned int c
, _locale_t locale
)
1602 pthreadmbcinfo mbcinfo
;
1605 mbcinfo
= locale
->mbcinfo
;
1607 mbcinfo
= get_mbcinfo();
1609 if(mbcinfo
->mbcodepage
== 932)
1611 /* Japanese/Katakana, CP 932 */
1612 return (c
>= 0xa1 && c
<= 0xdf);
1617 /*********************************************************************
1618 * _ismbbkana(MSVCRT.@)
1620 int CDECL
_ismbbkana(unsigned int c
)
1622 return _ismbbkana_l( c
, NULL
);
1625 /*********************************************************************
1626 * _ismbcdigit_l(MSVCRT.@)
1628 int CDECL
_ismbcdigit_l(unsigned int ch
, _locale_t locale
)
1630 return _iswdigit_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1633 /*********************************************************************
1634 * _ismbcdigit(MSVCRT.@)
1636 int CDECL
_ismbcdigit(unsigned int ch
)
1638 return _ismbcdigit_l( ch
, NULL
);
1641 /*********************************************************************
1642 * _ismbcgraph_l(MSVCRT.@)
1644 int CDECL
_ismbcgraph_l(unsigned int ch
, _locale_t locale
)
1646 return _iswgraph_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1649 /*********************************************************************
1650 * _ismbcgraph(MSVCRT.@)
1652 int CDECL
_ismbcgraph(unsigned int ch
)
1654 return _ismbcgraph_l( ch
, NULL
);
1657 /*********************************************************************
1658 * _ismbcalpha_l (MSVCRT.@)
1660 int CDECL
_ismbcalpha_l(unsigned int ch
, _locale_t locale
)
1662 return _iswalpha_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1665 /*********************************************************************
1666 * _ismbcalpha (MSVCRT.@)
1668 int CDECL
_ismbcalpha(unsigned int ch
)
1670 return _ismbcalpha_l( ch
, NULL
);
1673 /*********************************************************************
1674 * _ismbclower_l (MSVCRT.@)
1676 int CDECL
_ismbclower_l(unsigned int ch
, _locale_t locale
)
1678 return _iswlower_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1681 /*********************************************************************
1682 * _ismbclower (MSVCRT.@)
1684 int CDECL
_ismbclower(unsigned int ch
)
1686 return _ismbclower_l( ch
, NULL
);
1689 /*********************************************************************
1690 * _ismbcupper_l (MSVCRT.@)
1692 int CDECL
_ismbcupper_l(unsigned int ch
, _locale_t locale
)
1694 return _iswupper_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1697 /*********************************************************************
1698 * _ismbcupper (MSVCRT.@)
1700 int CDECL
_ismbcupper(unsigned int ch
)
1702 return _ismbcupper_l( ch
, NULL
);
1705 /*********************************************************************
1706 * _ismbcsymbol_l(MSVCRT.@)
1708 int CDECL
_ismbcsymbol_l(unsigned int ch
, _locale_t locale
)
1710 wchar_t wch
= msvcrt_mbc_to_wc_l( ch
, locale
);
1712 if (!GetStringTypeW(CT_CTYPE3
, &wch
, 1, &ctype
))
1714 WARN("GetStringTypeW failed on %x\n", ch
);
1717 return ((ctype
& C3_SYMBOL
) != 0);
1720 /*********************************************************************
1721 * _ismbcsymbol(MSVCRT.@)
1723 int CDECL
_ismbcsymbol(unsigned int ch
)
1725 return _ismbcsymbol_l(ch
, NULL
);
1728 /*********************************************************************
1729 * _ismbcalnum_l (MSVCRT.@)
1731 int CDECL
_ismbcalnum_l(unsigned int ch
, _locale_t locale
)
1733 return _iswalnum_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1736 /*********************************************************************
1737 * _ismbcalnum (MSVCRT.@)
1739 int CDECL
_ismbcalnum(unsigned int ch
)
1741 return _ismbcalnum_l( ch
, NULL
);
1744 /*********************************************************************
1745 * _ismbcspace_l (MSVCRT.@)
1747 int CDECL
_ismbcspace_l(unsigned int ch
, _locale_t locale
)
1749 return _iswspace_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1752 /*********************************************************************
1753 * _ismbcspace (MSVCRT.@)
1755 int CDECL
_ismbcspace(unsigned int ch
)
1757 return _ismbcspace_l( ch
, NULL
);
1760 /*********************************************************************
1761 * _ismbcprint_l (MSVCRT.@)
1763 int CDECL
_ismbcprint_l(unsigned int ch
, _locale_t locale
)
1765 return _iswprint_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1768 /*********************************************************************
1769 * _ismbcprint (MSVCRT.@)
1771 int CDECL
_ismbcprint(unsigned int ch
)
1773 return _ismbcprint_l( ch
, NULL
);
1776 /*********************************************************************
1777 * _ismbcpunct_l (MSVCRT.@)
1779 int CDECL
_ismbcpunct_l(unsigned int ch
, _locale_t locale
)
1781 return _iswpunct_l( msvcrt_mbc_to_wc_l(ch
, locale
), locale
);
1784 /*********************************************************************
1785 * _ismbcpunct(MSVCRT.@)
1787 int CDECL
_ismbcpunct(unsigned int ch
)
1789 return _ismbcpunct_l( ch
, NULL
);
1792 /*********************************************************************
1793 * _ismbchira_l(MSVCRT.@)
1795 int CDECL
_ismbchira_l(unsigned int c
, _locale_t locale
)
1797 pthreadmbcinfo mbcinfo
;
1800 mbcinfo
= locale
->mbcinfo
;
1802 mbcinfo
= get_mbcinfo();
1804 if(mbcinfo
->mbcodepage
== 932)
1806 /* Japanese/Hiragana, CP 932 */
1807 return (c
>= 0x829f && c
<= 0x82f1);
1812 /*********************************************************************
1813 * _ismbchira(MSVCRT.@)
1815 int CDECL
_ismbchira(unsigned int c
)
1817 return _ismbchira_l(c
, NULL
);
1820 /*********************************************************************
1821 * _ismbckata_l(MSVCRT.@)
1823 int CDECL
_ismbckata_l(unsigned int c
, _locale_t locale
)
1825 pthreadmbcinfo mbcinfo
;
1828 mbcinfo
= locale
->mbcinfo
;
1830 mbcinfo
= get_mbcinfo();
1832 if(mbcinfo
->mbcodepage
== 932)
1834 /* Japanese/Katakana, CP 932 */
1835 return (c
>= 0x8340 && c
<= 0x8396 && c
!= 0x837f);
1840 /*********************************************************************
1841 * _ismbckata(MSVCRT.@)
1843 int CDECL
_ismbckata(unsigned int c
)
1845 return _ismbckata_l(c
, NULL
);
1848 /*********************************************************************
1849 * _ismbblead_l(MSVCRT.@)
1851 int CDECL
_ismbblead_l(unsigned int c
, _locale_t locale
)
1853 pthreadmbcinfo mbcinfo
;
1856 mbcinfo
= get_mbcinfo();
1858 mbcinfo
= locale
->mbcinfo
;
1860 return (mbcinfo
->mbctype
[(c
&0xff) + 1] & _M1
) != 0;
1863 /*********************************************************************
1864 * _ismbblead(MSVCRT.@)
1866 int CDECL
_ismbblead(unsigned int c
)
1868 return _ismbblead_l(c
, NULL
);
1871 /*********************************************************************
1872 * _ismbbtrail_l(MSVCRT.@)
1874 int CDECL
_ismbbtrail_l(unsigned int c
, _locale_t locale
)
1876 pthreadmbcinfo mbcinfo
;
1879 mbcinfo
= get_mbcinfo();
1881 mbcinfo
= locale
->mbcinfo
;
1883 return (mbcinfo
->mbctype
[(c
&0xff) + 1] & _M2
) != 0;
1886 /*********************************************************************
1887 * _ismbbtrail(MSVCRT.@)
1889 int CDECL
_ismbbtrail(unsigned int c
)
1891 return _ismbbtrail_l(c
, NULL
);
1894 /*********************************************************************
1895 * _ismbclegal_l(MSVCRT.@)
1897 int CDECL
_ismbclegal_l(unsigned int c
, _locale_t locale
)
1899 return _ismbblead_l(HIBYTE(c
), locale
) && _ismbbtrail_l(LOBYTE(c
), locale
);
1902 /*********************************************************************
1903 * _ismbclegal(MSVCRT.@)
1905 int CDECL
_ismbclegal(unsigned int c
)
1907 return _ismbclegal_l(c
, NULL
);
1910 /*********************************************************************
1911 * _ismbslead_l(MSVCRT.@)
1913 int CDECL
_ismbslead_l(const unsigned char* start
, const unsigned char* str
, _locale_t locale
)
1915 pthreadmbcinfo mbcinfo
;
1918 if (!MSVCRT_CHECK_PMT(start
&& str
))
1922 mbcinfo
= locale
->mbcinfo
;
1924 mbcinfo
= get_mbcinfo();
1926 if(!mbcinfo
->ismbcodepage
)
1929 /* Lead bytes can also be trail bytes so we need to analyse the string
1931 while (start
<= str
)
1935 lead
= !lead
&& _ismbblead_l(*start
, locale
);
1939 return lead
? -1 : 0;
1942 /*********************************************************************
1943 * _ismbslead(MSVCRT.@)
1945 int CDECL
_ismbslead(const unsigned char* start
, const unsigned char* str
)
1947 return _ismbslead_l(start
, str
, NULL
);
1950 /*********************************************************************
1951 * _ismbstrail_l(MSVCRT.@)
1953 int CDECL
_ismbstrail_l(const unsigned char* start
, const unsigned char* str
, _locale_t locale
)
1955 if (!MSVCRT_CHECK_PMT(start
&& str
))
1958 /* Note: this function doesn't check _ismbbtrail */
1959 if ((str
> start
) && _ismbslead_l(start
, str
-1, locale
))
1965 /*********************************************************************
1966 * _ismbstrail(MSVCRT.@)
1968 int CDECL
_ismbstrail(const unsigned char* start
, const unsigned char* str
)
1970 return _ismbstrail_l(start
, str
, NULL
);
1973 /*********************************************************************
1974 * _mbbtype_l(MSVCRT.@)
1976 int CDECL
_mbbtype_l(unsigned char c
, int type
, _locale_t locale
)
1979 return _ismbbtrail_l(c
, locale
) ? _MBC_TRAIL
: _MBC_ILLEGAL
;
1981 return _ismbblead_l(c
, locale
) ? _MBC_LEAD
1982 : _isprint_l(c
, locale
) ? _MBC_SINGLE
: _MBC_ILLEGAL
;
1985 /*********************************************************************
1986 * _mbbtype(MSVCRT.@)
1988 int CDECL
_mbbtype(unsigned char c
, int type
)
1990 return _mbbtype_l(c
, type
, NULL
);
1993 /*********************************************************************
1994 * _mbsbtype (MSVCRT.@)
1996 int CDECL
_mbsbtype(const unsigned char *str
, size_t count
)
1999 const unsigned char *end
= str
+ count
;
2001 /* Lead bytes can also be trail bytes so we need to analyse the string.
2002 * Also we must return _MBC_ILLEGAL for chars past the end of the string
2004 while (str
< end
) /* Note: we skip the last byte - will check after the loop */
2007 return _MBC_ILLEGAL
;
2008 lead
= get_mbcinfo()->ismbcodepage
&& !lead
&& _ismbblead(*str
);
2013 if (_ismbbtrail(*str
))
2016 return _MBC_ILLEGAL
;
2018 if (_ismbblead(*str
))
2024 /*********************************************************************
2027 unsigned char* CDECL
_mbsset(unsigned char* str
, unsigned int c
)
2029 unsigned char* ret
= str
;
2031 if(!get_mbcinfo()->ismbcodepage
|| c
< 256)
2032 return u__strset(str
, c
); /* ASCII CP or SB char */
2034 c
&= 0xffff; /* Strip high bits */
2036 while(str
[0] && str
[1])
2042 str
[0] = '\0'; /* FIXME: OK to shorten? */
2047 /*********************************************************************
2048 * _mbsnbset(MSVCRT.@)
2050 unsigned char* CDECL
_mbsnbset(unsigned char *str
, unsigned int c
, size_t len
)
2052 unsigned char *ret
= str
;
2057 if(!get_mbcinfo()->ismbcodepage
|| c
< 256)
2058 return u__strnset(str
, c
, len
); /* ASCII CP or SB char */
2060 c
&= 0xffff; /* Strip high bits */
2062 while(str
[0] && str
[1] && (len
> 1))
2070 /* as per msdn pad with a blank character */
2077 /*********************************************************************
2078 * _mbsnset(MSVCRT.@)
2080 unsigned char* CDECL
_mbsnset(unsigned char* str
, unsigned int c
, size_t len
)
2082 unsigned char *ret
= str
;
2087 if(!get_mbcinfo()->ismbcodepage
|| c
< 256)
2088 return u__strnset(str
, c
, len
); /* ASCII CP or SB char */
2090 c
&= 0xffff; /* Strip high bits */
2092 while(str
[0] && str
[1] && len
--)
2098 str
[0] = '\0'; /* FIXME: OK to shorten? */
2103 /*********************************************************************
2104 * _mbsnccnt(MSVCRT.@)
2105 * 'c' is for 'character'.
2107 size_t CDECL
_mbsnccnt(const unsigned char* str
, size_t len
)
2110 if(get_mbcinfo()->ismbcodepage
)
2113 while(*str
&& len
-- > 0)
2115 if(_ismbblead(*str
))
2128 return min(ret
, len
); /* ASCII CP */
2131 /*********************************************************************
2132 * _mbsnbcnt(MSVCRT.@)
2133 * 'b' is for byte count.
2135 size_t CDECL
_mbsnbcnt(const unsigned char* str
, size_t len
)
2138 if(get_mbcinfo()->ismbcodepage
)
2140 const unsigned char* xstr
= str
;
2141 while(*xstr
&& len
-- > 0)
2143 if (_ismbblead(*xstr
++))
2149 return min(ret
, len
); /* ASCII CP */
2152 /*********************************************************************
2153 * _mbsnbcat(MSVCRT.@)
2155 unsigned char* CDECL
_mbsnbcat(unsigned char* dst
, const unsigned char* src
, size_t len
)
2157 if(get_mbcinfo()->ismbcodepage
)
2159 unsigned char *res
= dst
;
2161 if (_ismbblead(*dst
++)) {
2165 /* as per msdn overwrite the lead byte in front of '\0' */
2171 while (*src
&& len
--) *dst
++ = *src
++;
2175 return u_strncat(dst
, src
, len
); /* ASCII CP */
2178 int CDECL
_mbsnbcat_s(unsigned char *dst
, size_t size
, const unsigned char *src
, size_t len
)
2180 unsigned char *ptr
= dst
;
2183 if (!dst
&& !size
&& !src
&& !len
)
2186 if (!dst
|| !size
|| !src
)
2195 /* Find the null terminator of the destination buffer. */
2196 while (size
&& *ptr
)
2206 /* If necessary, check that the character preceding the null terminator is
2207 * a lead byte and move the pointer back by one for later overwrite. */
2208 if (ptr
!= dst
&& get_mbcinfo()->ismbcodepage
&& _ismbblead(*(ptr
- 1)))
2211 for (i
= 0; *src
&& i
< len
; i
++)
2228 /*********************************************************************
2229 * _mbsncat(MSVCRT.@)
2231 unsigned char* CDECL
_mbsncat(unsigned char* dst
, const unsigned char* src
, size_t len
)
2233 if(get_mbcinfo()->ismbcodepage
)
2235 unsigned char *res
= dst
;
2238 if (_ismbblead(*dst
++))
2241 while (*src
&& len
--)
2244 if(_ismbblead(*src
++))
2250 return u_strncat(dst
, src
, len
); /* ASCII CP */
2254 /*********************************************************************
2257 unsigned char* CDECL
_mbslwr(unsigned char* s
)
2259 unsigned char *ret
= s
;
2262 if (get_mbcinfo()->ismbcodepage
)
2267 c
= _mbctolower(_mbsnextc(s
));
2268 /* Note that I assume that the size of the character is unchanged */
2277 else for ( ; *s
; s
++) *s
= _tolower_l(*s
, NULL
);
2281 /*********************************************************************
2282 * _mbslwr_s_l(MSVCRT.@)
2284 int CDECL
_mbslwr_s_l(unsigned char* s
, size_t len
, _locale_t locale
)
2286 unsigned char *p
= s
;
2290 if (!MSVCRT_CHECK_PMT(s
&& len
))
2293 if (get_mbcinfo()->ismbcodepage
)
2296 for ( ; *s
&& len
> 0; len
--)
2298 c
= _mbctolower_l(_mbsnextc_l(s
, locale
), locale
);
2299 /* Note that I assume that the size of the character is unchanged */
2310 for ( ; *s
&& len
> 0; s
++, len
--)
2311 *s
= _tolower_l(*s
, locale
);
2314 if (!MSVCRT_CHECK_PMT(len
))
2323 /*********************************************************************
2324 * _mbslwr_s(MSVCRT.@)
2326 int CDECL
_mbslwr_s(unsigned char* str
, size_t len
)
2328 return _mbslwr_s_l(str
, len
, NULL
);
2331 /*********************************************************************
2334 unsigned char* CDECL
_mbsupr(unsigned char* s
)
2336 unsigned char *ret
= s
;
2339 if (get_mbcinfo()->ismbcodepage
)
2344 c
= _mbctoupper(_mbsnextc(s
));
2345 /* Note that I assume that the size of the character is unchanged */
2354 else for ( ; *s
; s
++) *s
= _toupper_l(*s
, NULL
);
2358 /*********************************************************************
2359 * _mbsupr_s_l(MSVCRT.@)
2361 int CDECL
_mbsupr_s_l(unsigned char* s
, size_t len
, _locale_t locale
)
2363 unsigned char *p
= s
;
2367 if (!MSVCRT_CHECK_PMT(s
&& len
))
2370 if (get_mbcinfo()->ismbcodepage
)
2373 for ( ; *s
&& len
> 0; len
--)
2375 c
= _mbctoupper_l(_mbsnextc_l(s
, locale
), locale
);
2376 /* Note that I assume that the size of the character is unchanged */
2387 for ( ; *s
&& len
> 0; s
++, len
--)
2388 *s
= _toupper_l(*s
, locale
);
2391 if (!MSVCRT_CHECK_PMT(len
))
2400 /*********************************************************************
2401 * _mbsupr_s(MSVCRT.@)
2403 int CDECL
_mbsupr_s(unsigned char* s
, size_t len
)
2405 return _mbsupr_s_l(s
, len
, NULL
);
2408 /*********************************************************************
2409 * _mbsspn_l (MSVCRT.@)
2411 size_t CDECL
_mbsspn_l(const unsigned char* string
,
2412 const unsigned char* set
, _locale_t locale
)
2414 const unsigned char *p
, *q
;
2416 for (p
= string
; *p
; p
++)
2418 for (q
= set
; *q
; q
++)
2420 if (_ismbblead_l(*q
, locale
))
2422 /* duplicate a bug in native implementation */
2425 if (p
[0] == q
[0] && p
[1] == q
[1])
2434 if (p
[0] == q
[0]) break;
2442 /*********************************************************************
2443 * _mbsspn (MSVCRT.@)
2445 size_t CDECL
_mbsspn(const unsigned char* string
, const unsigned char* set
)
2447 return _mbsspn_l(string
, set
, NULL
);
2450 /*********************************************************************
2451 * _mbsspnp (MSVCRT.@)
2453 unsigned char* CDECL
_mbsspnp(const unsigned char* string
, const unsigned char* set
)
2455 string
+= _mbsspn( string
, set
);
2456 return *string
? (unsigned char*)string
: NULL
;
2459 /*********************************************************************
2460 * _mbscspn_l (MSVCRT.@)
2462 size_t CDECL
_mbscspn_l(const unsigned char* str
,
2463 const unsigned char* cmp
, _locale_t locale
)
2465 const unsigned char *p
, *q
;
2467 for (p
= str
; *p
; p
++)
2469 for (q
= cmp
; *q
; q
++)
2471 if (_ismbblead_l(*q
, locale
))
2473 /* duplicate a bug in native implementation */
2474 if (!q
[1]) return 0;
2476 if (p
[0] == q
[0] && p
[1] == q
[1])
2480 else if (p
[0] == q
[0])
2487 /*********************************************************************
2488 * _mbscspn (MSVCRT.@)
2490 size_t CDECL
_mbscspn(const unsigned char* str
, const unsigned char* cmp
)
2492 return _mbscspn_l(str
, cmp
, NULL
);
2495 /*********************************************************************
2496 * _mbsrev (MSVCRT.@)
2498 unsigned char* CDECL
_mbsrev(unsigned char* str
)
2500 int i
, len
= _mbslen(str
);
2501 unsigned char *p
, *temp
=malloc(len
*2);
2506 /* unpack multibyte string to temp buffer */
2508 for(i
=0; i
<len
; i
++)
2522 /* repack it in the reverse order */
2524 for(i
=len
-1; i
>=0; i
--)
2526 if(_ismbblead(temp
[i
*2]))
2542 /*********************************************************************
2543 * _mbspbrk (MSVCRT.@)
2545 unsigned char* CDECL
_mbspbrk(const unsigned char* str
, const unsigned char* accept
)
2547 const unsigned char* p
;
2551 for(p
= accept
; *p
; p
+= (_ismbblead(*p
)?2:1) )
2554 if( !_ismbblead(*p
) || ( *(p
+1) == *(str
+1) ) )
2555 return (unsigned char*)str
;
2557 str
+= (_ismbblead(*str
)?2:1);
2564 * Functions depending on locale codepage
2567 /*********************************************************************
2570 * Unlike most of the multibyte string functions this function uses
2571 * the locale codepage, not the codepage set by _setmbcp
2573 int CDECL
mblen(const char* str
, size_t size
)
2575 if (str
&& *str
&& size
)
2577 if(get_locinfo()->mb_cur_max
== 1)
2578 return 1; /* ASCII CP */
2580 return !isleadbyte((unsigned char)*str
) ? 1 : (size
>1 ? 2 : -1);
2585 /*********************************************************************
2588 size_t CDECL
mbrlen(const char *str
, size_t len
, mbstate_t *state
)
2590 mbstate_t s
= (state
? *state
: 0);
2593 if(!len
|| !str
|| !*str
)
2596 if(get_locinfo()->mb_cur_max
== 1) {
2598 }else if(!s
&& isleadbyte((unsigned char)*str
)) {
2600 s
= (unsigned char)*str
;
2617 /*********************************************************************
2618 * _mbstrlen_l(MSVCRT.@)
2620 size_t CDECL
_mbstrlen_l(const char* str
, _locale_t locale
)
2622 pthreadlocinfo locinfo
;
2625 locinfo
= get_locinfo();
2627 locinfo
= locale
->locinfo
;
2629 if(locinfo
->mb_cur_max
> 1) {
2631 len
= MultiByteToWideChar(locinfo
->lc_codepage
, MB_ERR_INVALID_CHARS
,
2643 /*********************************************************************
2644 * _mbstrlen(MSVCRT.@)
2646 size_t CDECL
_mbstrlen(const char* str
)
2648 return _mbstrlen_l(str
, NULL
);
2651 /*********************************************************************
2652 * _mbtowc_l(MSVCRT.@)
2654 int CDECL
_mbtowc_l(wchar_t *dst
, const char* str
, size_t n
, _locale_t locale
)
2656 pthreadlocinfo locinfo
;
2660 locinfo
= get_locinfo();
2662 locinfo
= locale
->locinfo
;
2672 if(!locinfo
->lc_codepage
) {
2673 if(dst
) *dst
= (unsigned char)*str
;
2676 if(n
>=2 && _isleadbyte_l((unsigned char)*str
, locale
)) {
2677 if(!MultiByteToWideChar(locinfo
->lc_codepage
, 0, str
, 2, &tmpdst
, 1))
2679 if(dst
) *dst
= tmpdst
;
2682 if(!MultiByteToWideChar(locinfo
->lc_codepage
, 0, str
, 1, &tmpdst
, 1))
2684 if(dst
) *dst
= tmpdst
;
2688 /*********************************************************************
2691 int CDECL
mbtowc(wchar_t *dst
, const char* str
, size_t n
)
2693 return _mbtowc_l(dst
, str
, n
, NULL
);
2696 /*********************************************************************
2699 wint_t CDECL
btowc(int c
)
2701 unsigned char letter
= c
;
2706 if(!get_locinfo()->lc_codepage
)
2708 if(!MultiByteToWideChar(get_locinfo()->lc_codepage
,
2709 MB_ERR_INVALID_CHARS
, (LPCSTR
)&letter
, 1, &ret
, 1))
2715 /*********************************************************************
2718 size_t CDECL
mbrtowc(wchar_t *dst
, const char *str
,
2719 size_t n
, mbstate_t *state
)
2721 pthreadlocinfo locinfo
= get_locinfo();
2722 mbstate_t s
= (state
? *state
: 0);
2729 if(!n
|| !str
|| !*str
)
2732 if(locinfo
->mb_cur_max
== 1) {
2733 tmpstr
[len
++] = *str
;
2734 }else if(!s
&& isleadbyte((unsigned char)*str
)) {
2736 s
= (unsigned char)*str
;
2744 tmpstr
[len
++] = *str
;
2753 if(!MultiByteToWideChar(locinfo
->lc_codepage
, 0, tmpstr
, len
, dst
, dst
? 1 : 0))
2762 /*********************************************************************
2763 * _mbstowcs_l(MSVCRT.@)
2765 size_t CDECL
_mbstowcs_l(wchar_t *wcstr
, const char *mbstr
,
2766 size_t count
, _locale_t locale
)
2768 pthreadlocinfo locinfo
;
2777 locinfo
= get_locinfo();
2779 locinfo
= locale
->locinfo
;
2781 if(!locinfo
->lc_codepage
) {
2783 return strlen(mbstr
);
2785 for(i
=0; i
<count
; i
++) {
2786 wcstr
[i
] = (unsigned char)mbstr
[i
];
2787 if(!wcstr
[i
]) break;
2792 /* Ignore count parameter */
2794 size
= MultiByteToWideChar(locinfo
->lc_codepage
,
2795 MB_ERR_INVALID_CHARS
, mbstr
, -1, NULL
, 0);
2803 for(i
=0, size
=0; i
<count
; i
++) {
2804 if(mbstr
[size
] == '\0')
2807 size
+= (_isleadbyte_l((unsigned char)mbstr
[size
], locale
) ? 2 : 1);
2811 size
= MultiByteToWideChar(locinfo
->lc_codepage
,
2812 MB_ERR_INVALID_CHARS
, mbstr
, size
, wcstr
, count
);
2814 if(count
) wcstr
[0] = '\0';
2826 /*********************************************************************
2827 * mbstowcs(MSVCRT.@)
2829 size_t CDECL
mbstowcs(wchar_t *wcstr
,
2830 const char *mbstr
, size_t count
)
2832 return _mbstowcs_l(wcstr
, mbstr
, count
, NULL
);
2835 /*********************************************************************
2836 * _mbstowcs_s_l(MSVCRT.@)
2838 int CDECL
_mbstowcs_s_l(size_t *ret
, wchar_t *wcstr
,
2839 size_t size
, const char *mbstr
, size_t count
, _locale_t locale
)
2844 if(!wcstr
&& !size
) {
2845 conv
= _mbstowcs_l(NULL
, mbstr
, 0, locale
);
2851 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return EINVAL
;
2852 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) {
2853 if(size
) wcstr
[0] = '\0';
2857 if(count
==_TRUNCATE
|| size
<count
)
2862 conv
= _mbstowcs_l(wcstr
, mbstr
, conv
, locale
);
2864 wcstr
[conv
++] = '\0';
2865 else if(conv
==size
&& count
==_TRUNCATE
&& wcstr
[conv
-1]!='\0') {
2866 wcstr
[conv
-1] = '\0';
2868 }else if(conv
==size
&& wcstr
[conv
-1]!='\0') {
2869 MSVCRT_INVALID_PMT("wcstr[size] is too small", ERANGE
);
2880 /*********************************************************************
2881 * mbstowcs_s(MSVCRT.@)
2883 int CDECL
_mbstowcs_s(size_t *ret
, wchar_t *wcstr
,
2884 size_t size
, const char *mbstr
, size_t count
)
2886 return _mbstowcs_s_l(ret
, wcstr
, size
, mbstr
, count
, NULL
);
2889 /*********************************************************************
2890 * mbsrtowcs(MSVCRT.@)
2892 size_t CDECL
mbsrtowcs(wchar_t *wcstr
,
2893 const char **pmbstr
, size_t count
, mbstate_t *state
)
2895 mbstate_t s
= (state
? *state
: 0);
2900 if(!MSVCRT_CHECK_PMT(pmbstr
!= NULL
))
2904 while(!wcstr
|| count
>ret
) {
2905 int ch_len
= mbrtowc(&tmpdst
, p
, 2, &s
);
2907 wcstr
[ret
] = tmpdst
;
2911 }else if(ch_len
== 0) {
2912 if(wcstr
) *pmbstr
= NULL
;
2920 if(wcstr
) *pmbstr
= p
;
2924 /*********************************************************************
2925 * mbsrtowcs_s(MSVCRT.@)
2927 int CDECL
mbsrtowcs_s(size_t *ret
, wchar_t *wcstr
, size_t len
,
2928 const char **mbstr
, size_t count
, mbstate_t *state
)
2932 if(!ret
) ret
= &tmp
;
2933 if(!MSVCRT_CHECK_PMT(!!wcstr
== !!len
)) {
2938 *ret
= mbsrtowcs(wcstr
, mbstr
, count
>len
? len
: count
, state
);
2940 if(wcstr
) *wcstr
= 0;
2945 /* no place for terminating '\0' */
2946 if(wcstr
) *wcstr
= 0;
2949 if(wcstr
) wcstr
[(*ret
)-1] = 0;
2953 /*********************************************************************
2954 * _mbctohira_l (MSVCRT.@)
2956 * Converts a sjis katakana character to hiragana.
2958 unsigned int CDECL
_mbctohira_l(unsigned int c
, _locale_t locale
)
2960 if(_ismbckata_l(c
, locale
) && c
<= 0x8393)
2961 return (c
- 0x8340 - (c
>= 0x837f ? 1 : 0)) + 0x829f;
2965 /*********************************************************************
2966 * _mbctohira (MSVCRT.@)
2968 unsigned int CDECL
_mbctohira(unsigned int c
)
2970 return _mbctohira_l(c
, NULL
);
2973 /*********************************************************************
2974 * _mbctokata_l (MSVCRT.@)
2976 * Converts a sjis hiragana character to katakana.
2978 unsigned int CDECL
_mbctokata_l(unsigned int c
, _locale_t locale
)
2980 if(_ismbchira_l(c
, locale
))
2981 return (c
- 0x829f) + 0x8340 + (c
>= 0x82de ? 1 : 0);
2986 /*********************************************************************
2987 * _mbctokata (MSVCRT.@)
2989 unsigned int CDECL
_mbctokata(unsigned int c
)
2991 return _mbctokata_l(c
, NULL
);
2994 /*********************************************************************
2995 * _ismbcl0_l (MSVCRT.@)
2997 int CDECL
_ismbcl0_l(unsigned int c
, _locale_t locale
)
2999 pthreadmbcinfo mbcinfo
;
3002 mbcinfo
= get_mbcinfo();
3004 mbcinfo
= locale
->mbcinfo
;
3006 if(mbcinfo
->mbcodepage
== 932)
3009 return _ismbclegal_l(c
, locale
) && c
>= 0x8140 && c
<= 0x889e;
3015 /*********************************************************************
3016 * _ismbcl0 (MSVCRT.@)
3018 int CDECL
_ismbcl0(unsigned int c
)
3020 return _ismbcl0_l(c
, NULL
);
3023 /*********************************************************************
3024 * _ismbcl1_l (MSVCRT.@)
3026 int CDECL
_ismbcl1_l(unsigned int c
, _locale_t locale
)
3028 pthreadmbcinfo mbcinfo
;
3031 mbcinfo
= get_mbcinfo();
3033 mbcinfo
= locale
->mbcinfo
;
3035 if(mbcinfo
->mbcodepage
== 932)
3038 return _ismbclegal_l(c
, locale
) && c
>= 0x889f && c
<= 0x9872;
3044 /*********************************************************************
3045 * _ismbcl1 (MSVCRT.@)
3047 int CDECL
_ismbcl1(unsigned int c
)
3049 return _ismbcl1_l(c
, NULL
);
3052 /*********************************************************************
3053 * _ismbcl2_l (MSVCRT.@)
3055 int CDECL
_ismbcl2_l(unsigned int c
, _locale_t locale
)
3057 pthreadmbcinfo mbcinfo
;
3060 mbcinfo
= get_mbcinfo();
3062 mbcinfo
= locale
->mbcinfo
;
3064 if(mbcinfo
->mbcodepage
== 932)
3067 return _ismbclegal_l(c
, locale
) && c
>= 0x989f && c
<= 0xeaa4;
3073 /*********************************************************************
3074 * _ismbcl2 (MSVCRT.@)
3076 int CDECL
_ismbcl2(unsigned int c
)
3078 return _ismbcl2_l(c
, NULL
);