2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll mbcs functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
|
|
|
* Copyright 2000 Jon Griffths
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2001-01-11 00:59:25 +01:00
|
|
|
* FIXME
|
2001-01-22 03:22:26 +01:00
|
|
|
* Not currently binary compatible with win32. MSVCRT_mbctype must be
|
2001-01-11 00:59:25 +01:00
|
|
|
* populated correctly and the ismb* functions should reference it.
|
|
|
|
*/
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
#include <stdio.h>
|
2015-04-24 14:48:04 +02:00
|
|
|
#include <limits.h>
|
2011-10-12 11:55:35 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
2002-11-19 01:52:38 +01:00
|
|
|
#include "wine/unicode.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2008-07-21 14:47:55 +02:00
|
|
|
unsigned char MSVCRT_mbctype[257] = { 0 };
|
2007-08-20 05:19:37 +02:00
|
|
|
|
|
|
|
/* It seems that the data about valid trail bytes is not available from kernel32
|
|
|
|
* so we have to store is here. The format is the same as for lead bytes in CPINFO */
|
|
|
|
struct cp_extra_info_t
|
|
|
|
{
|
|
|
|
int cp;
|
|
|
|
BYTE TrailBytes[MAX_LEADBYTES];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct cp_extra_info_t g_cpextrainfo[] =
|
|
|
|
{
|
|
|
|
{932, {0x40, 0x7e, 0x80, 0xfc, 0, 0}},
|
|
|
|
{936, {0x40, 0xfe, 0, 0}},
|
|
|
|
{949, {0x41, 0xfe, 0, 0}},
|
|
|
|
{950, {0x40, 0x7e, 0xa1, 0xfe, 0, 0}},
|
2010-02-23 06:43:12 +01:00
|
|
|
{1361, {0x31, 0x7e, 0x81, 0xfe, 0, 0}},
|
2007-08-23 03:41:32 +02:00
|
|
|
{20932, {1, 255, 0, 0}}, /* seems to give different results on different systems */
|
2007-08-20 05:19:37 +02:00
|
|
|
{0, {1, 255, 0, 0}} /* match all with FIXME */
|
|
|
|
};
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2012-03-21 15:02:10 +01:00
|
|
|
/* Maps cp932 single byte character to multi byte character */
|
|
|
|
static const unsigned char mbbtombc_932[] = {
|
|
|
|
0x40,0x49,0x68,0x94,0x90,0x93,0x95,0x66,0x69,0x6a,0x96,0x7b,0x43,0x7c,0x44,0x5e,
|
|
|
|
0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x46,0x47,0x83,0x81,0x84,0x48,
|
|
|
|
0x97,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,
|
|
|
|
0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x76,
|
|
|
|
0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x51,0x65,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
|
|
|
|
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x50,
|
|
|
|
0x42,0x75,0x76,0x41,0x45,0x92,0x40,0x42,0x44,0x46,0x48,0x83,0x85,0x87,0x62,
|
|
|
|
0x5b,0x41,0x43,0x45,0x47,0x49,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,
|
|
|
|
0x5e,0x60,0x63,0x65,0x67,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x71,0x74,0x77,0x7a,0x7d,
|
|
|
|
0x7e,0x80,0x81,0x82,0x84,0x86,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8f,0x93,0x4a,0x4b };
|
|
|
|
|
2010-02-24 04:52:52 +01:00
|
|
|
/* Maps multibyte cp932 punctuation marks to single byte equivalents */
|
|
|
|
static const unsigned char mbctombb_932_punct[] = {
|
|
|
|
0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e,
|
|
|
|
0x7e,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x00,0x00,0x2f,0x00,
|
|
|
|
0x00,0x00,0x7c,0x00,0x00,0x60,0x27,0x00,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,0x7b,
|
|
|
|
0x7d,0x00,0x00,0x00,0x00,0xa2,0xa3,0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,0x00,
|
|
|
|
0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5c,
|
|
|
|
0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40};
|
|
|
|
|
|
|
|
/* Maps multibyte cp932 hiragana/katakana to single-byte equivalents */
|
|
|
|
static const unsigned char mbctombb_932_kana[] = {
|
|
|
|
0xa7,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8,0xb8,
|
|
|
|
0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0,0xc0,
|
|
|
|
0xc1,0xc1,0xaf,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xca,
|
|
|
|
0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0,0xd1,
|
|
|
|
0xd2,0xd3,0xac,0xd4,0xad,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xb2,
|
|
|
|
0xb4,0xa6,0xdd,0xb3,0xb6,0xb9};
|
|
|
|
|
2002-12-19 05:21:30 +01:00
|
|
|
static MSVCRT_wchar_t msvcrt_mbc_to_wc(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t chW;
|
2002-11-19 01:52:38 +01:00
|
|
|
char mbch[2];
|
|
|
|
int n_chars;
|
|
|
|
|
|
|
|
if (ch <= 0xff) {
|
|
|
|
mbch[0] = ch;
|
|
|
|
n_chars = 1;
|
|
|
|
} else {
|
|
|
|
mbch[0] = (ch >> 8) & 0xff;
|
|
|
|
mbch[1] = ch & 0xff;
|
|
|
|
n_chars = 2;
|
|
|
|
}
|
2011-10-12 11:55:35 +02:00
|
|
|
if (!MultiByteToWideChar(get_mbcinfo()->mbcodepage, 0, mbch, n_chars, &chW, 1))
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
|
|
|
WARN("MultiByteToWideChar failed on %x\n", ch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return chW;
|
|
|
|
}
|
|
|
|
|
2009-05-27 11:38:58 +02:00
|
|
|
static inline MSVCRT_size_t u_strlen( const unsigned char *str )
|
2005-08-23 20:49:18 +02:00
|
|
|
{
|
|
|
|
return strlen( (const char*) str );
|
|
|
|
}
|
|
|
|
|
2009-05-27 11:38:58 +02:00
|
|
|
static inline unsigned char* u_strncat( unsigned char* dst, const unsigned char* src, MSVCRT_size_t len )
|
2005-08-23 20:49:18 +02:00
|
|
|
{
|
|
|
|
return (unsigned char*)strncat( (char*)dst, (const char*)src, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int u_strcmp( const unsigned char *s1, const unsigned char *s2 )
|
|
|
|
{
|
2019-10-31 09:35:40 +01:00
|
|
|
return MSVCRT_strcmp( (const char*)s1, (const char*)s2 );
|
2005-08-23 20:49:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int u_strcasecmp( const unsigned char *s1, const unsigned char *s2 )
|
|
|
|
{
|
2019-03-26 11:31:09 +01:00
|
|
|
return MSVCRT__stricmp( (const char*)s1, (const char*)s2 );
|
2005-08-23 20:49:18 +02:00
|
|
|
}
|
|
|
|
|
2009-05-27 11:38:58 +02:00
|
|
|
static inline int u_strncmp( const unsigned char *s1, const unsigned char *s2, MSVCRT_size_t len )
|
2005-08-23 20:49:18 +02:00
|
|
|
{
|
2019-10-31 09:35:40 +01:00
|
|
|
return MSVCRT_strncmp( (const char*)s1, (const char*)s2, len );
|
2005-08-23 20:49:18 +02:00
|
|
|
}
|
|
|
|
|
2009-05-27 11:38:58 +02:00
|
|
|
static inline int u_strncasecmp( const unsigned char *s1, const unsigned char *s2, MSVCRT_size_t len )
|
2005-08-23 20:49:18 +02:00
|
|
|
{
|
2019-03-26 11:31:13 +01:00
|
|
|
return MSVCRT__strnicmp( (const char*)s1, (const char*)s2, len );
|
2005-08-23 20:49:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u_strchr( const unsigned char *s, unsigned char x )
|
|
|
|
{
|
|
|
|
return (unsigned char*) strchr( (const char*)s, x );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u_strrchr( const unsigned char *s, unsigned char x )
|
|
|
|
{
|
|
|
|
return (unsigned char*) strrchr( (const char*)s, x );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u__strset( unsigned char *s, unsigned char c )
|
|
|
|
{
|
|
|
|
return (unsigned char*) _strset( (char*)s, c);
|
|
|
|
}
|
|
|
|
|
2009-05-27 11:38:58 +02:00
|
|
|
static inline unsigned char *u__strnset( unsigned char *s, unsigned char c, MSVCRT_size_t len )
|
2005-08-23 20:49:18 +02:00
|
|
|
{
|
2010-03-29 00:00:26 +02:00
|
|
|
return (unsigned char*) MSVCRT__strnset( (char*)s, c, len );
|
2005-08-23 20:49:18 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __p__mbctype (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL __p__mbctype(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
return get_mbcinfo()->mbctype;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-11-01 00:20:16 +01:00
|
|
|
* __p___mb_cur_max(MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2012-11-01 00:20:16 +01:00
|
|
|
int* CDECL __p___mb_cur_max(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
return &get_locinfo()->mb_cur_max;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2012-11-01 00:20:16 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* ___mb_cur_max_func(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT____mb_cur_max_func(void)
|
|
|
|
{
|
|
|
|
return get_locinfo()->mb_cur_max;
|
|
|
|
}
|
|
|
|
|
2018-01-07 06:05:31 +01:00
|
|
|
#if _MSVCR_VER>=80
|
2014-04-21 14:32:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* ___mb_cur_max_l_func (MSVCR80.@)
|
|
|
|
*/
|
2020-01-27 03:15:16 +01:00
|
|
|
int CDECL ___mb_cur_max_l_func(MSVCRT__locale_t locale)
|
2010-05-05 13:37:18 +02:00
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
2010-05-05 13:37:18 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2010-05-05 13:37:18 +02:00
|
|
|
|
2020-01-27 03:15:16 +01:00
|
|
|
return locinfo->mb_cur_max;
|
2010-05-05 13:37:18 +02:00
|
|
|
}
|
2018-01-07 06:05:31 +01:00
|
|
|
#endif
|
2010-05-05 13:37:18 +02:00
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
/*********************************************************************
|
2011-10-13 12:24:59 +02:00
|
|
|
* INTERNAL: _setmbcp_l
|
2007-08-20 05:19:37 +02:00
|
|
|
*/
|
2011-10-26 14:10:22 +02:00
|
|
|
int _setmbcp_l(int cp, LCID lcid, MSVCRT_pthreadmbcinfo mbcinfo)
|
2007-08-20 05:19:37 +02:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
const char format[] = ".%d";
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
int newcp;
|
|
|
|
CPINFO cpi;
|
|
|
|
BYTE *bytes;
|
|
|
|
WORD chartypes[256];
|
|
|
|
char bufA[256];
|
|
|
|
WCHAR bufW[256];
|
|
|
|
int charcount;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2011-10-13 12:24:59 +02:00
|
|
|
if(!mbcinfo)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
switch (cp)
|
|
|
|
{
|
|
|
|
case _MB_CP_ANSI:
|
|
|
|
newcp = GetACP();
|
|
|
|
break;
|
|
|
|
case _MB_CP_OEM:
|
|
|
|
newcp = GetOEMCP();
|
|
|
|
break;
|
|
|
|
case _MB_CP_LOCALE:
|
2011-10-12 11:55:35 +02:00
|
|
|
newcp = get_locinfo()->lc_codepage;
|
2011-10-12 11:55:20 +02:00
|
|
|
if(newcp)
|
|
|
|
break;
|
|
|
|
/* fall through (C locale) */
|
2007-08-20 05:19:37 +02:00
|
|
|
case _MB_CP_SBCS:
|
|
|
|
newcp = 20127; /* ASCII */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newcp = cp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-26 14:10:22 +02:00
|
|
|
if(lcid == -1) {
|
|
|
|
sprintf(bufA, format, newcp);
|
2018-05-09 17:36:17 +02:00
|
|
|
mbcinfo->mblcid = MSVCRT_locale_to_LCID(bufA, NULL, NULL);
|
2011-10-26 14:10:22 +02:00
|
|
|
} else {
|
|
|
|
mbcinfo->mblcid = lcid;
|
|
|
|
}
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(mbcinfo->mblcid == -1)
|
|
|
|
{
|
|
|
|
WARN("Can't assign LCID to codepage (%d)\n", mbcinfo->mblcid);
|
|
|
|
mbcinfo->mblcid = 0;
|
|
|
|
}
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
if (!GetCPInfo(newcp, &cpi))
|
|
|
|
{
|
|
|
|
WARN("Codepage %d not found\n", newcp);
|
2008-02-27 12:24:09 +01:00
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
2007-08-20 05:19:37 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup the _mbctype */
|
2011-10-12 11:55:35 +02:00
|
|
|
memset(mbcinfo->mbctype, 0, sizeof(unsigned char[257]));
|
|
|
|
memset(mbcinfo->mbcasemap, 0, sizeof(unsigned char[256]));
|
2007-08-20 05:19:37 +02:00
|
|
|
|
|
|
|
bytes = cpi.LeadByte;
|
|
|
|
while (bytes[0] || bytes[1])
|
|
|
|
{
|
|
|
|
for (i = bytes[0]; i <= bytes[1]; i++)
|
2011-10-12 11:55:35 +02:00
|
|
|
mbcinfo->mbctype[i + 1] |= _M1;
|
2007-08-20 05:19:37 +02:00
|
|
|
bytes += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi.MaxCharSize > 1)
|
|
|
|
{
|
|
|
|
/* trail bytes not available through kernel32 but stored in a structure in msvcrt */
|
|
|
|
struct cp_extra_info_t *cpextra = g_cpextrainfo;
|
2007-08-22 19:47:01 +02:00
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
mbcinfo->ismbcodepage = 1;
|
2007-08-20 05:19:37 +02:00
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (cpextra->cp == 0 || cpextra->cp == newcp)
|
|
|
|
{
|
|
|
|
if (cpextra->cp == 0)
|
|
|
|
FIXME("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp);
|
|
|
|
|
|
|
|
bytes = cpextra->TrailBytes;
|
|
|
|
while (bytes[0] || bytes[1])
|
|
|
|
{
|
|
|
|
for (i = bytes[0]; i <= bytes[1]; i++)
|
2011-10-12 11:55:35 +02:00
|
|
|
mbcinfo->mbctype[i + 1] |= _M2;
|
2007-08-20 05:19:37 +02:00
|
|
|
bytes += 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cpextra++;
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 19:47:01 +02:00
|
|
|
else
|
2011-10-12 11:55:35 +02:00
|
|
|
mbcinfo->ismbcodepage = 0;
|
2007-08-20 05:19:37 +02:00
|
|
|
|
|
|
|
/* we can't use GetStringTypeA directly because we don't have a locale - only a code page
|
|
|
|
*/
|
|
|
|
charcount = 0;
|
|
|
|
for (i = 0; i < 256; i++)
|
2011-10-12 11:55:35 +02:00
|
|
|
if (!(mbcinfo->mbctype[i + 1] & _M1))
|
2007-08-20 05:19:37 +02:00
|
|
|
bufA[charcount++] = i;
|
|
|
|
|
|
|
|
ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount);
|
|
|
|
if (ret != charcount)
|
|
|
|
ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
|
|
|
|
|
|
|
|
GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes);
|
|
|
|
|
2011-10-13 12:24:59 +02:00
|
|
|
charcount = 0;
|
2007-08-20 05:19:37 +02:00
|
|
|
for (i = 0; i < 256; i++)
|
2011-10-12 11:55:35 +02:00
|
|
|
if (!(mbcinfo->mbctype[i + 1] & _M1))
|
2007-08-20 05:19:37 +02:00
|
|
|
{
|
2011-10-13 12:24:59 +02:00
|
|
|
if (chartypes[charcount] & C1_UPPER)
|
|
|
|
{
|
|
|
|
mbcinfo->mbctype[i + 1] |= _SBUP;
|
|
|
|
bufW[charcount] = tolowerW(bufW[charcount]);
|
|
|
|
}
|
|
|
|
else if (chartypes[charcount] & C1_LOWER)
|
|
|
|
{
|
|
|
|
mbcinfo->mbctype[i + 1] |= _SBLOW;
|
|
|
|
bufW[charcount] = toupperW(bufW[charcount]);
|
|
|
|
}
|
|
|
|
charcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = WideCharToMultiByte(newcp, 0, bufW, charcount, bufA, charcount, NULL, NULL);
|
|
|
|
if (ret != charcount)
|
|
|
|
ERR("WideCharToMultiByte failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
|
|
|
|
|
|
|
|
charcount = 0;
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
if(!(mbcinfo->mbctype[i + 1] & _M1))
|
|
|
|
{
|
|
|
|
if(mbcinfo->mbctype[i] & (C1_UPPER|C1_LOWER))
|
|
|
|
mbcinfo->mbcasemap[i] = bufA[charcount];
|
|
|
|
charcount++;
|
2007-08-20 05:19:37 +02:00
|
|
|
}
|
2011-10-13 12:24:59 +02:00
|
|
|
}
|
2007-08-20 05:19:37 +02:00
|
|
|
|
|
|
|
if (newcp == 932) /* CP932 only - set _MP and _MS */
|
|
|
|
{
|
|
|
|
/* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
|
|
|
|
* and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes
|
|
|
|
* it hard. As this is set only for codepage 932 we hardcode it what gives
|
|
|
|
* also faster execution.
|
|
|
|
*/
|
|
|
|
for (i = 161; i <= 165; i++)
|
2011-10-12 11:55:35 +02:00
|
|
|
mbcinfo->mbctype[i + 1] |= _MP;
|
2007-08-20 05:19:37 +02:00
|
|
|
for (i = 166; i <= 223; i++)
|
2011-10-12 11:55:35 +02:00
|
|
|
mbcinfo->mbctype[i + 1] |= _MS;
|
2007-08-20 05:19:37 +02:00
|
|
|
}
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
mbcinfo->mbcodepage = newcp;
|
2011-10-13 12:24:59 +02:00
|
|
|
if(MSVCRT_locale && mbcinfo == MSVCRT_locale->mbcinfo)
|
2011-10-12 11:55:35 +02:00
|
|
|
memcpy(MSVCRT_mbctype, MSVCRT_locale->mbcinfo->mbctype, sizeof(MSVCRT_mbctype));
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-13 12:24:59 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _setmbcp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _setmbcp(int cp)
|
|
|
|
{
|
2011-10-26 14:10:22 +02:00
|
|
|
return _setmbcp_l(cp, -1, NULL);
|
2011-10-13 12:24:59 +02:00
|
|
|
}
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _getmbcp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _getmbcp(void)
|
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
return get_mbcinfo()->mbcodepage;
|
2007-08-20 05:19:37 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnextc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbsnextc(const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-20 07:34:12 +02:00
|
|
|
if(_ismbblead(*str))
|
2001-01-11 00:59:25 +01:00
|
|
|
return *str << 8 | str[1];
|
2007-08-20 07:34:12 +02:00
|
|
|
return *str;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbctolower(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbctolower(unsigned int c)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(c))
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
FIXME("Handle MBC chars\n");
|
|
|
|
return c;
|
|
|
|
}
|
2019-03-26 11:31:01 +01:00
|
|
|
return MSVCRT__tolower_l(c, NULL); /* ASCII CP or SB char */
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbctoupper(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbctoupper(unsigned int c)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(c))
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
FIXME("Handle MBC chars\n");
|
|
|
|
return c;
|
|
|
|
}
|
2019-03-26 11:31:06 +01:00
|
|
|
return MSVCRT__toupper_l(c, NULL); /* ASCII CP or SB char */
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2010-02-24 04:52:52 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbctombb (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _mbctombb(unsigned int c)
|
|
|
|
{
|
|
|
|
unsigned int value;
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->mbcodepage == 932)
|
2010-02-24 04:52:52 +01:00
|
|
|
{
|
|
|
|
if(c >= 0x829f && c <= 0x82f1) /* Hiragana */
|
|
|
|
return mbctombb_932_kana[c - 0x829f];
|
|
|
|
if(c >= 0x8340 && c <= 0x8396 && c != 0x837f) /* Katakana */
|
|
|
|
return mbctombb_932_kana[c - 0x8340 - (c >= 0x837f ? 1 : 0)];
|
|
|
|
if(c >= 0x8140 && c <= 0x8197) /* Punctuation */
|
|
|
|
{
|
|
|
|
value = mbctombb_932_punct[c - 0x8140];
|
|
|
|
return value ? value : c;
|
|
|
|
}
|
|
|
|
if((c >= 0x824f && c <= 0x8258) || /* Fullwidth digits */
|
|
|
|
(c >= 0x8260 && c <= 0x8279)) /* Fullwidth capitals letters */
|
|
|
|
return c - 0x821f;
|
|
|
|
if(c >= 0x8281 && c <= 0x829a) /* Fullwidth small letters */
|
|
|
|
return c - 0x8220;
|
|
|
|
/* all other cases return c */
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2009-01-24 00:37:57 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbcjistojms(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Converts a jis character to sjis.
|
|
|
|
* Based on description from
|
|
|
|
* http://www.slayers.ne.jp/~oouchi/code/jistosjis.html
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _mbcjistojms(unsigned int c)
|
|
|
|
{
|
|
|
|
/* Conversion takes place only when codepage is 932.
|
|
|
|
In all other cases, c is returned unchanged */
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->mbcodepage == 932)
|
2009-01-24 00:37:57 +01:00
|
|
|
{
|
|
|
|
if(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e &&
|
|
|
|
LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e)
|
|
|
|
{
|
|
|
|
if(HIBYTE(c) % 2)
|
|
|
|
c += 0x1f;
|
|
|
|
else
|
|
|
|
c += 0x7d;
|
|
|
|
|
2012-03-21 15:02:16 +01:00
|
|
|
if(LOBYTE(c) >= 0x7F)
|
2009-01-24 00:37:57 +01:00
|
|
|
c += 0x1;
|
|
|
|
|
|
|
|
c = (((HIBYTE(c) - 0x21)/2 + 0x81) << 8) | LOBYTE(c);
|
|
|
|
|
|
|
|
if(HIBYTE(c) > 0x9f)
|
|
|
|
c += 0x4000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; /* Codepage is 932, but c can't be converted */
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2012-03-15 15:41:30 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbcjmstojis(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Converts a sjis character to jis.
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _mbcjmstojis(unsigned int c)
|
|
|
|
{
|
|
|
|
/* Conversion takes place only when codepage is 932.
|
|
|
|
In all other cases, c is returned unchanged */
|
|
|
|
if(get_mbcinfo()->mbcodepage == 932)
|
|
|
|
{
|
2012-03-15 15:41:33 +01:00
|
|
|
if(_ismbclegal(c) && HIBYTE(c) < 0xf0)
|
|
|
|
{
|
|
|
|
if(HIBYTE(c) >= 0xe0)
|
|
|
|
c -= 0x4000;
|
|
|
|
|
|
|
|
c = (((HIBYTE(c) - 0x81)*2 + 0x21) << 8) | LOBYTE(c);
|
|
|
|
|
|
|
|
if(LOBYTE(c) > 0x7f)
|
|
|
|
c -= 0x1;
|
|
|
|
|
|
|
|
if(LOBYTE(c) > 0x9d)
|
|
|
|
c += 0x83;
|
|
|
|
else
|
|
|
|
c -= 0x1f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; /* Codepage is 932, but c can't be converted */
|
2012-03-15 15:41:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsdec(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cur)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2015-12-21 11:22:55 +01:00
|
|
|
if(start >= cur)
|
|
|
|
return NULL;
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2005-04-18 11:54:03 +02:00
|
|
|
return (unsigned char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1);
|
2001-12-05 23:11:35 +01:00
|
|
|
|
2005-04-18 11:54:03 +02:00
|
|
|
return (unsigned char *)cur - 1; /* ASCII CP or SB char */
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:11:17 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbclen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _mbclen(const unsigned char* str)
|
|
|
|
{
|
|
|
|
return _ismbblead(*str) ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsinc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsinc(const unsigned char* str)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-23 04:14:30 +02:00
|
|
|
return (unsigned char *)(str + _mbclen(str));
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsninc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsninc(const unsigned char* str, MSVCRT_size_t num)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-23 04:14:30 +02:00
|
|
|
if(!str)
|
2001-12-05 23:11:35 +01:00
|
|
|
return NULL;
|
2007-08-23 04:14:30 +02:00
|
|
|
|
|
|
|
while (num > 0 && *str)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-23 04:14:30 +02:00
|
|
|
if (_ismbblead(*str))
|
|
|
|
{
|
|
|
|
if (!*(str+1))
|
|
|
|
break;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
num--;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2007-08-23 04:14:30 +02:00
|
|
|
|
|
|
|
return (unsigned char*)str;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2017-10-05 19:39:25 +02:00
|
|
|
* _mbsnlen_l(MSVCRT.@)
|
2001-12-05 23:11:35 +01:00
|
|
|
*/
|
2017-10-05 19:39:25 +02:00
|
|
|
MSVCRT_size_t CDECL _mbsnlen_l(const unsigned char *str,
|
|
|
|
MSVCRT_size_t maxsize, MSVCRT__locale_t locale)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2017-10-05 19:39:25 +02:00
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
MSVCRT_size_t i = 0, len = 0;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
if(!mbcinfo->ismbcodepage)
|
|
|
|
return MSVCRT_strnlen((const char*)str, maxsize);
|
|
|
|
|
|
|
|
while(i<maxsize && str[i])
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2017-10-05 19:39:25 +02:00
|
|
|
if (_ismbblead_l(str[i], locale))
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
if (!str[i]) /* count only full chars */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
len++;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2017-10-05 19:39:25 +02:00
|
|
|
return i < maxsize ? len : maxsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbslen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbslen(const unsigned char* str)
|
|
|
|
{
|
|
|
|
return _mbsnlen_l(str, -1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbslen_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbslen_l(const unsigned char* str, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return _mbsnlen_l(str, -1, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnlen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbsnlen(const unsigned char* str, MSVCRT_size_t maxsize)
|
|
|
|
{
|
|
|
|
return _mbsnlen_l(str, maxsize, NULL);
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2017-10-06 12:07:18 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbccpy_s_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbccpy_s_l(unsigned char* dest, MSVCRT_size_t maxsize,
|
|
|
|
int *copied, const unsigned char* src, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
if(copied) *copied = 0;
|
|
|
|
if(!MSVCRT_CHECK_PMT(dest != NULL && maxsize >= 1)) return MSVCRT_EINVAL;
|
|
|
|
dest[0] = 0;
|
|
|
|
if(!MSVCRT_CHECK_PMT(src != NULL)) return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
if(_ismbblead_l(*src, locale)) {
|
|
|
|
if(!src[1]) {
|
|
|
|
if(copied) *copied = 1;
|
|
|
|
*MSVCRT__errno() = MSVCRT_EILSEQ;
|
|
|
|
return MSVCRT_EILSEQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(maxsize < 2) {
|
|
|
|
MSVCRT_INVALID_PMT("dst buffer is too small", MSVCRT_ERANGE);
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest++ = *src++;
|
|
|
|
*dest = *src;
|
|
|
|
if(copied) *copied = 2;
|
|
|
|
}else {
|
|
|
|
*dest = *src;
|
|
|
|
if(copied) *copied = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbccpy(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL _mbccpy(unsigned char* dest, const unsigned char* src)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2017-10-06 12:07:18 +02:00
|
|
|
_mbccpy_s_l(dest, 2, NULL, src, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbccpy_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL _mbccpy_l(unsigned char* dest, const unsigned char* src,
|
|
|
|
MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
_mbccpy_s_l(dest, 2, NULL, src, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbccpy_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbccpy_s(unsigned char* dest, MSVCRT_size_t maxsize,
|
|
|
|
int *copied, const unsigned char* src)
|
|
|
|
{
|
|
|
|
return _mbccpy_s_l(dest, maxsize, copied, src, NULL);
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsncpy(MSVCRT.@)
|
2007-08-22 19:47:01 +02:00
|
|
|
* REMARKS
|
|
|
|
* The parameter n is the number or characters to copy, not the size of
|
|
|
|
* the buffer. Use _mbsnbcpy for a function analogical to strncpy
|
2001-12-05 23:11:35 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
unsigned char* ret = dst;
|
2001-12-05 23:11:35 +01:00
|
|
|
if(!n)
|
|
|
|
return dst;
|
2011-10-12 11:55:35 +02:00
|
|
|
if (get_mbcinfo()->ismbcodepage)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
while (*src && n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
n--;
|
2007-08-22 19:47:01 +02:00
|
|
|
if (_ismbblead(*src))
|
|
|
|
{
|
|
|
|
if (!*(src+1))
|
|
|
|
{
|
|
|
|
*dst++ = 0;
|
|
|
|
*dst++ = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = *src++;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
}
|
2005-04-25 17:51:45 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if (!(*dst++ = *src++)) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n--) *dst++ = 0;
|
|
|
|
return ret;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2007-11-15 16:32:33 +01:00
|
|
|
/*********************************************************************
|
2014-05-19 11:42:58 +02:00
|
|
|
* _mbsnbcpy_s_l(MSVCRT.@)
|
2007-11-15 16:32:33 +01:00
|
|
|
* REMARKS
|
|
|
|
* Unlike _mbsnbcpy this function does not pad the rest of the dest
|
|
|
|
* string with 0
|
|
|
|
*/
|
2014-05-19 11:42:58 +02:00
|
|
|
int CDECL _mbsnbcpy_s_l(unsigned char* dst, MSVCRT_size_t size,
|
|
|
|
const unsigned char* src, MSVCRT_size_t n, MSVCRT__locale_t locale)
|
2007-11-15 16:32:33 +01:00
|
|
|
{
|
|
|
|
MSVCRT_size_t pos = 0;
|
|
|
|
|
|
|
|
if(!dst || size == 0)
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_EINVAL;
|
2007-11-15 16:32:33 +01:00
|
|
|
if(!src)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_EINVAL;
|
2007-11-15 16:32:33 +01:00
|
|
|
}
|
|
|
|
if(!n)
|
|
|
|
return 0;
|
|
|
|
|
2014-05-19 11:42:58 +02:00
|
|
|
if((locale ? locale->mbcinfo : get_mbcinfo())->ismbcodepage)
|
2007-11-15 16:32:33 +01:00
|
|
|
{
|
2016-05-25 21:50:55 +02:00
|
|
|
BOOL is_lead = FALSE;
|
2007-11-15 16:32:33 +01:00
|
|
|
while (*src && n)
|
|
|
|
{
|
|
|
|
if(pos == size)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_ERANGE;
|
2007-11-15 16:32:33 +01:00
|
|
|
}
|
|
|
|
is_lead = (!is_lead && _ismbblead(*src));
|
|
|
|
n--;
|
|
|
|
dst[pos++] = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_lead) /* if string ends with a lead, remove it */
|
|
|
|
dst[pos - 1] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if(pos == size)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_ERANGE;
|
2007-11-15 16:32:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(*src)) break;
|
|
|
|
dst[pos++] = *src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pos < size)
|
|
|
|
dst[pos] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
2008-02-27 12:26:15 +01:00
|
|
|
return MSVCRT_ERANGE;
|
2007-11-15 16:32:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-19 11:42:58 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcpy_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsnbcpy_s(unsigned char* dst, MSVCRT_size_t size, const unsigned char* src, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
return _mbsnbcpy_s_l(dst, size, src, n, NULL);
|
|
|
|
}
|
|
|
|
|
2014-05-19 11:43:05 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscpy_s_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbscpy_s_l(unsigned char *dst, MSVCRT_size_t size,
|
|
|
|
const unsigned char *src, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return _mbsnbcpy_s_l(dst, size, src, -1, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbscpy_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbscpy_s(unsigned char *dst, MSVCRT_size_t size, const unsigned char *src)
|
|
|
|
{
|
|
|
|
return _mbscpy_s_l(dst, size, src, NULL);
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcpy(MSVCRT.@)
|
2007-08-22 19:47:01 +02:00
|
|
|
* REMARKS
|
|
|
|
* Like strncpy this function doesn't enforce the string to be
|
|
|
|
* NUL-terminated
|
2001-12-05 23:11:35 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
unsigned char* ret = dst;
|
2001-12-05 23:11:35 +01:00
|
|
|
if(!n)
|
|
|
|
return dst;
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2016-05-25 21:50:55 +02:00
|
|
|
BOOL is_lead = FALSE;
|
2007-08-22 19:47:01 +02:00
|
|
|
while (*src && n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-22 19:47:01 +02:00
|
|
|
is_lead = (!is_lead && _ismbblead(*src));
|
2001-12-05 23:11:35 +01:00
|
|
|
n--;
|
2007-08-22 19:47:01 +02:00
|
|
|
*dst++ = *src++;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2007-08-22 19:47:01 +02:00
|
|
|
|
|
|
|
if (is_lead) /* if string ends with a lead, remove it */
|
|
|
|
*(dst - 1) = 0;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2005-04-25 17:51:45 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if (!(*dst++ = *src++)) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n--) *dst++ = 0;
|
|
|
|
return ret;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscmp(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2015-04-24 14:48:04 +02:00
|
|
|
if (!str || !cmp) return INT_MAX;
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
do {
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
2001-04-10 23:16:07 +02:00
|
|
|
strc = _mbsnextc(str);
|
|
|
|
cmpc = _mbsnextc(cmp);
|
2001-01-11 00:59:25 +01:00
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
|
|
|
} while(1);
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strcmp(str, cmp); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2012-12-12 11:16:57 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbicoll_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsnbicoll_l(const unsigned char *str1, const unsigned char *str2, MSVCRT_size_t len, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
if(!mbcinfo->ismbcodepage)
|
|
|
|
return MSVCRT__strnicoll_l((const char*)str1, (const char*)str2, len, locale);
|
|
|
|
return CompareStringA(mbcinfo->mblcid, NORM_IGNORECASE, (const char*)str1, len, (const char*)str2, len)-CSTR_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsicoll_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsicoll_l(const unsigned char *str1, const unsigned char *str2, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return _mbsnbicoll_l(str1, str2, -1, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbicoll(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsnbicoll(const unsigned char *str1, const unsigned char *str2, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
return _mbsnbicoll_l(str1, str2, len, NULL);
|
|
|
|
}
|
|
|
|
|
2003-01-31 04:20:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsicoll(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp)
|
2003-01-31 04:20:25 +01:00
|
|
|
{
|
2015-10-01 18:29:10 +02:00
|
|
|
#if _MSVCR_VER>=60 && _MSVCR_VER<=71
|
|
|
|
return CompareStringA(get_mbcinfo()->mblcid, NORM_IGNORECASE,
|
|
|
|
(const char*)str, -1, (const char*)cmp, -1)-CSTR_EQUAL;
|
|
|
|
#else
|
2012-12-12 11:16:57 +01:00
|
|
|
return _mbsnbicoll_l(str, cmp, -1, NULL);
|
2015-10-01 18:29:10 +02:00
|
|
|
#endif
|
2003-01-31 04:20:25 +01:00
|
|
|
}
|
|
|
|
|
2012-12-12 11:17:10 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcoll_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsnbcoll_l(const unsigned char *str1, const unsigned char *str2, MSVCRT_size_t len, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
if(!mbcinfo->ismbcodepage)
|
2013-04-29 06:45:16 +02:00
|
|
|
return MSVCRT__strncoll_l((const char*)str1, (const char*)str2, len, locale);
|
2012-12-12 11:17:10 +01:00
|
|
|
return CompareStringA(mbcinfo->mblcid, 0, (const char*)str1, len, (const char*)str2, len)-CSTR_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbscoll_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbscoll_l(const unsigned char *str1, const unsigned char *str2, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return _mbsnbcoll_l(str1, str2, -1, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcoll(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsnbcoll(const unsigned char *str1, const unsigned char *str2, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
return _mbsnbcoll_l(str1, str2, len, NULL);
|
|
|
|
}
|
|
|
|
|
2005-08-24 20:14:06 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscoll(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp)
|
2005-08-24 20:14:06 +02:00
|
|
|
{
|
2015-10-01 18:29:10 +02:00
|
|
|
#if _MSVCR_VER>=60 && _MSVCR_VER<=71
|
|
|
|
return CompareStringA(get_mbcinfo()->mblcid, 0,
|
|
|
|
(const char*)str, -1, (const char*)cmp, -1)-CSTR_EQUAL;
|
|
|
|
#else
|
2012-12-12 11:17:10 +01:00
|
|
|
return _mbsnbcoll_l(str, cmp, -1, NULL);
|
2015-10-01 18:29:10 +02:00
|
|
|
#endif
|
2005-08-24 20:14:06 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsicmp(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsicmp(const unsigned char* str, const unsigned char* cmp)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
do {
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
strc = _mbctolower(_mbsnextc(str));
|
|
|
|
cmpc = _mbctolower(_mbsnextc(cmp));
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
|
|
|
} while(1);
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strcasecmp(str, cmp); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsncmp(MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsncmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(!len)
|
|
|
|
return 0;
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while(len--)
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
int inc;
|
2001-01-11 00:59:25 +01:00
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
2001-04-10 23:16:07 +02:00
|
|
|
strc = _mbsnextc(str);
|
|
|
|
cmpc = _mbsnextc(cmp);
|
2001-01-11 00:59:25 +01:00
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
2001-12-05 23:11:35 +01:00
|
|
|
inc=(strc > 255) ? 2 : 1; /* Equal, use same increment */
|
|
|
|
str += inc;
|
|
|
|
cmp += inc;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0; /* Matched len chars */
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncmp(str, cmp, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsnbcmp(MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!len)
|
|
|
|
return 0;
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
int clen;
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*str))
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
strc=(len>=2)?_mbsnextc(str):0;
|
|
|
|
clen=2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strc=*str;
|
|
|
|
clen=1;
|
|
|
|
}
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*cmp))
|
2001-12-05 23:11:35 +01:00
|
|
|
cmpc=(len>=2)?_mbsnextc(cmp):0;
|
|
|
|
else
|
2012-03-21 15:02:17 +01:00
|
|
|
cmpc=*cmp;
|
2001-12-05 23:11:35 +01:00
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
len -= clen;
|
|
|
|
str += clen;
|
|
|
|
cmp += clen;
|
|
|
|
}
|
|
|
|
return 0; /* Matched len chars */
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncmp(str,cmp,len);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsnicmp(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Compare two multibyte strings case insensitively to 'len' characters.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsnicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
/* FIXME: No tolower() for mb strings yet */
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while(len--)
|
|
|
|
{
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
strc = _mbctolower(_mbsnextc(str));
|
|
|
|
cmpc = _mbctolower(_mbsnextc(cmp));
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* Equal, use same increment */
|
|
|
|
}
|
|
|
|
return 0; /* Matched len chars */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncasecmp(str, cmp, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2002-04-02 04:42:58 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbicmp(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsnbicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2002-04-02 04:42:58 +02:00
|
|
|
{
|
|
|
|
if (!len)
|
|
|
|
return 0;
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2002-04-02 04:42:58 +02:00
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
int clen;
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*str))
|
2002-04-02 04:42:58 +02:00
|
|
|
{
|
|
|
|
strc=(len>=2)?_mbsnextc(str):0;
|
|
|
|
clen=2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strc=*str;
|
|
|
|
clen=1;
|
|
|
|
}
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*cmp))
|
2002-04-02 04:42:58 +02:00
|
|
|
cmpc=(len>=2)?_mbsnextc(cmp):0;
|
|
|
|
else
|
2012-03-21 15:02:17 +01:00
|
|
|
cmpc=*cmp;
|
2002-04-02 04:42:58 +02:00
|
|
|
strc = _mbctolower(strc);
|
|
|
|
cmpc = _mbctolower(cmpc);
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
len -= clen;
|
|
|
|
str += clen;
|
|
|
|
cmp += clen;
|
|
|
|
}
|
|
|
|
return 0; /* Matched len bytes */
|
|
|
|
}
|
2007-08-04 17:48:02 +02:00
|
|
|
return u_strncasecmp(str,cmp,len);
|
2002-04-02 04:42:58 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscat (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char * CDECL _mbscat( unsigned char *dst, const unsigned char *src )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
strcat( (char *)dst, (const char *)src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2015-07-06 19:40:10 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscat_s_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbscat_s_l( unsigned char *dst, MSVCRT_size_t size,
|
|
|
|
const unsigned char *src, MSVCRT__locale_t locale )
|
|
|
|
{
|
|
|
|
MSVCRT_size_t i, j;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT(dst != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(src != NULL)) return MSVCRT_EINVAL;
|
|
|
|
|
|
|
|
for(i=0; i<size; i++)
|
|
|
|
if(!dst[i]) break;
|
|
|
|
if(i == size) {
|
|
|
|
MSVCRT_INVALID_PMT("dst is not NULL-terminated", MSVCRT_EINVAL);
|
|
|
|
if(size) dst[0] = 0;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i && _ismbblead_l(dst[i-1], locale)) {
|
|
|
|
ret = MSVCRT_EILSEQ;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j=0; src[j] && i+j<size; j++)
|
|
|
|
dst[i+j] = src[j];
|
|
|
|
if(i+j == size) {
|
2015-08-07 15:40:50 +02:00
|
|
|
MSVCRT_INVALID_PMT("dst buffer is too small", MSVCRT_ERANGE);
|
2015-07-06 19:40:10 +02:00
|
|
|
dst[0] = 0;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(j && _ismbblead_l(src[j-1], locale)) {
|
|
|
|
ret = MSVCRT_EILSEQ;
|
|
|
|
j--;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst[i+j] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbscat_s (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbscat_s( unsigned char *dst, MSVCRT_size_t size, const unsigned char *src )
|
|
|
|
{
|
|
|
|
return _mbscat_s_l(dst, size, src, NULL);
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscpy (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbscpy( unsigned char *dst, const unsigned char *src )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
strcpy( (char *)dst, (const char *)src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsstr (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char * CDECL _mbsstr(const unsigned char *haystack, const unsigned char *needle)
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
2019-10-28 13:29:15 +01:00
|
|
|
return (unsigned char *)MSVCRT_strstr( (const char *)haystack, (const char *)needle );
|
2006-01-14 17:40:29 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbschr(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Find a multibyte character in a multibyte string.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned int c;
|
|
|
|
while (1)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
c = _mbsnextc(s);
|
|
|
|
if (c == x)
|
|
|
|
return (unsigned char*)s;
|
|
|
|
if (!c)
|
|
|
|
return NULL;
|
|
|
|
s += c > 255 ? 2 : 1;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strchr(s, x); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsrchr(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsrchr(const unsigned char* s, unsigned int x)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
unsigned char* match=NULL;
|
|
|
|
if(!s)
|
|
|
|
return NULL;
|
|
|
|
while (1) {
|
|
|
|
c = _mbsnextc(s);
|
|
|
|
if (c == x)
|
|
|
|
match=(unsigned char*)s;
|
|
|
|
if (!c)
|
|
|
|
return match;
|
|
|
|
s +=(c > 255) ? 2 : 1;
|
|
|
|
}
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strrchr(s, x);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2003-02-01 01:45:22 +01:00
|
|
|
/*********************************************************************
|
2013-04-30 14:29:11 +02:00
|
|
|
* _mbstok_s_l(MSVCRT.@)
|
2003-02-01 01:45:22 +01:00
|
|
|
*/
|
2013-04-30 14:29:11 +02:00
|
|
|
unsigned char* CDECL _mbstok_s_l(unsigned char *str, const unsigned char *delim,
|
|
|
|
unsigned char **ctx, MSVCRT__locale_t locale)
|
2003-02-01 01:45:22 +01:00
|
|
|
{
|
2013-04-30 14:29:11 +02:00
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
unsigned int c;
|
2003-02-01 01:45:22 +01:00
|
|
|
|
2013-04-30 14:29:11 +02:00
|
|
|
if(!MSVCRT_CHECK_PMT(delim != NULL)) return NULL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(ctx != NULL)) return NULL;
|
|
|
|
if(!MSVCRT_CHECK_PMT(str || *ctx)) return NULL;
|
|
|
|
|
|
|
|
if(locale)
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
else
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
|
|
|
|
if(!mbcinfo->ismbcodepage)
|
|
|
|
return (unsigned char*)MSVCRT_strtok_s((char*)str, (const char*)delim, (char**)ctx);
|
|
|
|
|
|
|
|
if(!str)
|
|
|
|
str = *ctx;
|
|
|
|
|
|
|
|
while((c=_mbsnextc(str)) && _mbschr(delim, c))
|
|
|
|
str += c>255 ? 2 : 1;
|
|
|
|
if(!*str)
|
2016-08-18 11:49:04 +02:00
|
|
|
{
|
|
|
|
*ctx = str;
|
2013-04-30 14:29:11 +02:00
|
|
|
return NULL;
|
2016-08-18 11:49:04 +02:00
|
|
|
}
|
2013-04-30 14:29:11 +02:00
|
|
|
|
|
|
|
*ctx = str + (c>255 ? 2 : 1);
|
|
|
|
while((c=_mbsnextc(*ctx)) && !_mbschr(delim, c))
|
|
|
|
*ctx += c>255 ? 2 : 1;
|
|
|
|
if (**ctx) {
|
|
|
|
*(*ctx)++ = 0;
|
|
|
|
if(c > 255)
|
|
|
|
*(*ctx)++ = 0;
|
2003-02-01 01:45:22 +01:00
|
|
|
}
|
2013-04-30 14:29:11 +02:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbstok_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* CDECL _mbstok_s(unsigned char *str,
|
|
|
|
const unsigned char *delim, unsigned char **ctx)
|
|
|
|
{
|
|
|
|
return _mbstok_s_l(str, delim, ctx, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbstok_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* CDECL _mbstok_l(unsigned char *str,
|
|
|
|
const unsigned char *delim, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return _mbstok_s_l(str, delim, &msvcrt_get_thread_data()->mbstok_next, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbstok(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* CDECL _mbstok(unsigned char *str, const unsigned char *delim)
|
|
|
|
{
|
2013-06-21 12:17:33 +02:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
2014-04-21 13:08:20 +02:00
|
|
|
#if _MSVCR_VER == 0
|
2013-06-21 12:17:33 +02:00
|
|
|
if(!str && !data->mbstok_next)
|
|
|
|
return NULL;
|
2014-04-21 13:08:20 +02:00
|
|
|
#endif
|
2013-06-21 12:17:33 +02:00
|
|
|
|
|
|
|
return _mbstok_s_l(str, delim, &data->mbstok_next, NULL);
|
2003-02-01 01:45:22 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbbtombc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbbtombc(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2012-03-21 15:02:10 +01:00
|
|
|
if(get_mbcinfo()->mbcodepage == 932)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2012-03-21 15:02:10 +01:00
|
|
|
if(c >= 0x20 && c <= 0x7e) {
|
|
|
|
if((c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) || (c >= 0x30 && c <= 0x39))
|
|
|
|
return mbbtombc_932[c - 0x20] | 0x8200;
|
|
|
|
else
|
|
|
|
return mbbtombc_932[c - 0x20] | 0x8100;
|
|
|
|
}
|
|
|
|
else if(c >= 0xa1 && c <= 0xdf) {
|
|
|
|
if(c >= 0xa6 && c <= 0xdd && c != 0xb0)
|
|
|
|
return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8300;
|
|
|
|
else
|
|
|
|
return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8100;
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2012-03-21 15:02:10 +01:00
|
|
|
return c; /* not Japanese or no MB char */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2007-02-06 00:34:31 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbbtype(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbbtype(unsigned char c, int type)
|
|
|
|
{
|
|
|
|
if (type == 1)
|
|
|
|
{
|
|
|
|
if ((c >= 0x20 && c <= 0x7e) || (c >= 0xa1 && c <= 0xdf))
|
|
|
|
return _MBC_SINGLE;
|
|
|
|
else if ((c >= 0x40 && c <= 0x7e) || (c >= 0x80 && c <= 0xfc))
|
|
|
|
return _MBC_TRAIL;
|
|
|
|
else
|
|
|
|
return _MBC_ILLEGAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((c >= 0x20 && c <= 0x7e) || (c >= 0xa1 && c <= 0xdf))
|
|
|
|
return _MBC_SINGLE;
|
|
|
|
else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc))
|
|
|
|
return _MBC_LEAD;
|
|
|
|
else
|
|
|
|
return _MBC_ILLEGAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbbkana(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbbkana(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: use lc_ctype when supported, not lc_all */
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->mbcodepage == 932)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Japanese/Katakana, CP 932 */
|
2001-01-12 20:56:22 +01:00
|
|
|
return (c >= 0xa1 && c <= 0xdf);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcdigit(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcdigit(unsigned int ch)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_DIGIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcgraph(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcgraph(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcalpha (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcalpha(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbclower (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbclower(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcupper (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcupper(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_LOWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcsymbol(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcsymbol(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
WORD ctype;
|
|
|
|
if (!GetStringTypeW(CT_CTYPE3, &wch, 1, &ctype))
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2002-11-19 01:52:38 +01:00
|
|
|
WARN("GetStringTypeW failed on %x\n", ch);
|
|
|
|
return 0;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2002-11-19 01:52:38 +01:00
|
|
|
return ((ctype & C3_SYMBOL) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcalnum (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcalnum(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & (C1_ALPHA | C1_DIGIT));
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcspace (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcspace(unsigned int ch)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_SPACE);
|
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
|
2002-11-19 01:52:38 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcprint (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcprint(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA | C1_SPACE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcpunct(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcpunct(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_PUNCT);
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbchira(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbchira(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->mbcodepage == 932)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Japanese/Hiragana, CP 932 */
|
2001-01-12 20:56:22 +01:00
|
|
|
return (c >= 0x829f && c <= 0x82f1);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbckata(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbckata(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->mbcodepage == 932)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Japanese/Katakana, CP 932 */
|
2001-01-12 20:56:22 +01:00
|
|
|
return (c >= 0x8340 && c <= 0x8396 && c != 0x837f);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 19:40:01 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbblead_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbblead_l(unsigned int c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
return (mbcinfo->mbctype[(c&0xff) + 1] & _M1) != 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbblead(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbblead(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2015-07-06 19:40:01 +02:00
|
|
|
return _ismbblead_l(c, NULL);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2019-02-14 14:35:02 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbbtrail_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbbtrail_l(unsigned int c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
return (mbcinfo->mbctype[(c&0xff) + 1] & _M2) != 0;
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbbtrail(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbbtrail(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2019-02-14 14:35:02 +01:00
|
|
|
return _ismbbtrail_l(c, NULL);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2019-02-14 14:35:07 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbclegal_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbclegal_l(unsigned int c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
return _ismbblead_l(HIBYTE(c), locale) && _ismbbtrail_l(LOBYTE(c), locale);
|
|
|
|
}
|
|
|
|
|
2010-02-23 07:05:44 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbclegal(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbclegal(unsigned int c)
|
|
|
|
{
|
2019-02-14 14:35:07 +01:00
|
|
|
return _ismbclegal_l(c, NULL);
|
2010-02-23 07:05:44 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbslead(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbslead(const unsigned char* start, const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-24 02:26:14 +02:00
|
|
|
int lead = 0;
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(!get_mbcinfo()->ismbcodepage)
|
2007-08-24 02:26:14 +02:00
|
|
|
return 0;
|
|
|
|
|
2007-08-29 21:43:57 +02:00
|
|
|
/* Lead bytes can also be trail bytes so we need to analyse the string
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2007-08-24 02:26:14 +02:00
|
|
|
while (start <= str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-24 02:26:14 +02:00
|
|
|
if (!*start)
|
|
|
|
return 0;
|
|
|
|
lead = !lead && _ismbblead(*start);
|
|
|
|
start++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2007-08-24 02:26:14 +02:00
|
|
|
|
|
|
|
return lead ? -1 : 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbstrail(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbstrail(const unsigned char* start, const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-24 02:26:14 +02:00
|
|
|
/* Note: this function doesn't check _ismbbtrail */
|
|
|
|
if ((str > start) && _ismbslead(start, str-1))
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2007-08-24 03:11:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsbtype (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsbtype(const unsigned char *str, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
int lead = 0;
|
|
|
|
const unsigned char *end = str + count;
|
|
|
|
|
|
|
|
/* Lead bytes can also be trail bytes so we need to analyse the string.
|
|
|
|
* Also we must return _MBC_ILLEGAL for chars past the end of the string
|
|
|
|
*/
|
|
|
|
while (str < end) /* Note: we skip the last byte - will check after the loop */
|
|
|
|
{
|
|
|
|
if (!*str)
|
|
|
|
return _MBC_ILLEGAL;
|
2011-10-12 11:55:35 +02:00
|
|
|
lead = get_mbcinfo()->ismbcodepage && !lead && _ismbblead(*str);
|
2007-08-24 03:11:43 +02:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lead)
|
|
|
|
if (_ismbbtrail(*str))
|
|
|
|
return _MBC_TRAIL;
|
|
|
|
else
|
|
|
|
return _MBC_ILLEGAL;
|
|
|
|
else
|
|
|
|
if (_ismbblead(*str))
|
|
|
|
return _MBC_LEAD;
|
|
|
|
else
|
|
|
|
return _MBC_SINGLE;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsset(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsset(unsigned char* str, unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(!get_mbcinfo()->ismbcodepage || c < 256)
|
2005-08-23 20:49:18 +02:00
|
|
|
return u__strset(str, c); /* ASCII CP or SB char */
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
c &= 0xffff; /* Strip high bits */
|
|
|
|
|
|
|
|
while(str[0] && str[1])
|
|
|
|
{
|
|
|
|
*str++ = c >> 8;
|
|
|
|
*str++ = c & 0xff;
|
|
|
|
}
|
|
|
|
if(str[0])
|
|
|
|
str[0] = '\0'; /* FIXME: OK to shorten? */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-02-01 01:45:22 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbset(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnbset(unsigned char *str, unsigned int c, MSVCRT_size_t len)
|
2003-02-01 01:45:22 +01:00
|
|
|
{
|
|
|
|
unsigned char *ret = str;
|
|
|
|
|
|
|
|
if(!len)
|
|
|
|
return ret;
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(!get_mbcinfo()->ismbcodepage || c < 256)
|
2005-08-23 20:49:18 +02:00
|
|
|
return u__strnset(str, c, len); /* ASCII CP or SB char */
|
2003-02-01 01:45:22 +01:00
|
|
|
|
|
|
|
c &= 0xffff; /* Strip high bits */
|
|
|
|
|
|
|
|
while(str[0] && str[1] && (len > 1))
|
|
|
|
{
|
|
|
|
*str++ = c >> 8;
|
|
|
|
len--;
|
|
|
|
*str++ = c & 0xff;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
if(len && str[0]) {
|
|
|
|
/* as per msdn pad with a blank character */
|
|
|
|
str[0] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnset(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char *ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
if(!len)
|
|
|
|
return ret;
|
|
|
|
|
2011-10-12 11:55:35 +02:00
|
|
|
if(!get_mbcinfo()->ismbcodepage || c < 256)
|
2005-08-23 20:49:18 +02:00
|
|
|
return u__strnset(str, c, len); /* ASCII CP or SB char */
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
c &= 0xffff; /* Strip high bits */
|
|
|
|
|
|
|
|
while(str[0] && str[1] && len--)
|
|
|
|
{
|
|
|
|
*str++ = c >> 8;
|
|
|
|
*str++ = c & 0xff;
|
|
|
|
}
|
|
|
|
if(len && str[0])
|
|
|
|
str[0] = '\0'; /* FIXME: OK to shorten? */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnccnt(MSVCRT.@)
|
2001-09-07 20:34:45 +02:00
|
|
|
* 'c' is for 'character'.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t ret;
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
ret=0;
|
2001-01-11 00:59:25 +01:00
|
|
|
while(*str && len-- > 0)
|
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
if(_ismbblead(*str))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!len)
|
|
|
|
break;
|
2001-01-11 00:59:25 +01:00
|
|
|
len--;
|
2001-12-05 23:11:35 +01:00
|
|
|
str++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
str++;
|
2001-12-05 23:11:35 +01:00
|
|
|
ret++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
ret=u_strlen(str);
|
2001-12-05 23:11:35 +01:00
|
|
|
return min(ret, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2001-09-07 20:34:45 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcnt(MSVCRT.@)
|
|
|
|
* 'b' is for byte count.
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len)
|
2001-09-07 20:34:45 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t ret;
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-09-07 20:34:45 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
const unsigned char* xstr = str;
|
2001-09-07 20:34:45 +02:00
|
|
|
while(*xstr && len-- > 0)
|
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*xstr++))
|
2001-09-07 20:34:45 +02:00
|
|
|
xstr++;
|
|
|
|
}
|
|
|
|
return xstr-str;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
ret=u_strlen(str);
|
2001-12-05 23:11:35 +01:00
|
|
|
return min(ret, len); /* ASCII CP */
|
2001-09-07 20:34:45 +02:00
|
|
|
}
|
|
|
|
|
2003-02-15 00:26:58 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcat(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
|
2003-02-15 00:26:58 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2003-02-15 00:26:58 +01:00
|
|
|
{
|
2005-08-23 20:49:18 +02:00
|
|
|
unsigned char *res = dst;
|
2003-02-15 00:26:58 +01:00
|
|
|
while (*dst) {
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*dst++)) {
|
2003-02-15 00:26:58 +01:00
|
|
|
if (*dst) {
|
|
|
|
dst++;
|
|
|
|
} else {
|
|
|
|
/* as per msdn overwrite the lead byte in front of '\0' */
|
|
|
|
dst--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*src && len--) *dst++ = *src++;
|
|
|
|
*dst = '\0';
|
|
|
|
return res;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncat(dst, src, len); /* ASCII CP */
|
2003-02-15 00:26:58 +01:00
|
|
|
}
|
|
|
|
|
2010-10-21 09:55:43 +02:00
|
|
|
int CDECL _mbsnbcat_s(unsigned char *dst, MSVCRT_size_t size, const unsigned char *src, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
unsigned char *ptr = dst;
|
|
|
|
MSVCRT_size_t i;
|
|
|
|
|
|
|
|
if (!dst && !size && !src && !len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!dst || !size || !src)
|
|
|
|
{
|
|
|
|
if (dst && size)
|
|
|
|
*dst = '\0';
|
|
|
|
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the null terminator of the destination buffer. */
|
|
|
|
while (size && *ptr)
|
|
|
|
size--, ptr++;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
*dst = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If necessary, check that the character preceding the null terminator is
|
|
|
|
* a lead byte and move the pointer back by one for later overwrite. */
|
2011-10-12 11:55:51 +02:00
|
|
|
if (ptr != dst && get_mbcinfo()->ismbcodepage && _ismbblead(*(ptr - 1)))
|
2010-10-21 09:55:43 +02:00
|
|
|
size++, ptr--;
|
|
|
|
|
|
|
|
for (i = 0; *src && i < len; i++)
|
|
|
|
{
|
|
|
|
*ptr++ = *src++;
|
|
|
|
size--;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
*dst = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-15 00:26:58 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsncat(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-10-12 11:55:35 +02:00
|
|
|
if(get_mbcinfo()->ismbcodepage)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2005-08-23 20:49:18 +02:00
|
|
|
unsigned char *res = dst;
|
2001-12-05 23:11:35 +01:00
|
|
|
while (*dst)
|
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*dst++))
|
2001-12-05 23:11:35 +01:00
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
while (*src && len--)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
*dst++ = *src;
|
2011-10-12 11:55:51 +02:00
|
|
|
if(_ismbblead(*src++))
|
2001-12-05 23:11:35 +01:00
|
|
|
*dst++ = *src++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
*dst = '\0';
|
2001-01-11 00:59:25 +01:00
|
|
|
return res;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncat(dst, src, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2001-07-11 22:13:14 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbslwr(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbslwr(unsigned char* s)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2006-01-24 12:24:05 +01:00
|
|
|
unsigned char *ret = s;
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
2011-10-12 11:55:35 +02:00
|
|
|
if (get_mbcinfo()->ismbcodepage)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
while (*s)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
c = _mbctolower(_mbsnextc(s));
|
|
|
|
/* Note that I assume that the size of the character is unchanged */
|
|
|
|
if (c > 255)
|
|
|
|
{
|
|
|
|
*s++=(c>>8);
|
|
|
|
c=c & 0xff;
|
|
|
|
}
|
|
|
|
*s++=c;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2019-03-26 11:31:01 +01:00
|
|
|
else for ( ; *s; s++) *s = MSVCRT__tolower_l(*s, NULL);
|
2006-01-24 12:24:05 +01:00
|
|
|
return ret;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-20 02:19:02 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbslwr_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbslwr_s(unsigned char* s, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
if (!s && !len)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (!s || !len)
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
2011-10-12 11:55:35 +02:00
|
|
|
if (get_mbcinfo()->ismbcodepage)
|
2011-03-20 02:19:02 +01:00
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
for ( ; *s && len > 0; len--)
|
|
|
|
{
|
|
|
|
c = _mbctolower(_mbsnextc(s));
|
|
|
|
/* Note that I assume that the size of the character is unchanged */
|
|
|
|
if (c > 255)
|
|
|
|
{
|
|
|
|
*s++=(c>>8);
|
|
|
|
c=c & 0xff;
|
|
|
|
}
|
|
|
|
*s++=c;
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 11:31:01 +01:00
|
|
|
else for ( ; *s && len > 0; s++, len--) *s = MSVCRT__tolower_l(*s, NULL);
|
2011-03-20 02:19:02 +01:00
|
|
|
if (*s)
|
|
|
|
{
|
|
|
|
*s = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-17 21:02:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsupr(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsupr(unsigned char* s)
|
2001-09-17 21:02:21 +02:00
|
|
|
{
|
2006-01-24 12:24:05 +01:00
|
|
|
unsigned char *ret = s;
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
2011-10-12 11:55:35 +02:00
|
|
|
if (get_mbcinfo()->ismbcodepage)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
while (*s)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
c = _mbctoupper(_mbsnextc(s));
|
|
|
|
/* Note that I assume that the size of the character is unchanged */
|
|
|
|
if (c > 255)
|
|
|
|
{
|
|
|
|
*s++=(c>>8);
|
|
|
|
c=c & 0xff;
|
|
|
|
}
|
|
|
|
*s++=c;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2019-03-26 11:31:06 +01:00
|
|
|
else for ( ; *s; s++) *s = MSVCRT__toupper_l(*s, NULL);
|
2006-01-24 12:24:05 +01:00
|
|
|
return ret;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-20 02:17:12 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsupr_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsupr_s(unsigned char* s, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
if (!s && !len)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (!s || !len)
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
2011-10-12 11:55:35 +02:00
|
|
|
if (get_mbcinfo()->ismbcodepage)
|
2011-03-20 02:17:12 +01:00
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
for ( ; *s && len > 0; len--)
|
|
|
|
{
|
|
|
|
c = _mbctoupper(_mbsnextc(s));
|
|
|
|
/* Note that I assume that the size of the character is unchanged */
|
|
|
|
if (c > 255)
|
|
|
|
{
|
|
|
|
*s++=(c>>8);
|
|
|
|
c=c & 0xff;
|
|
|
|
}
|
|
|
|
*s++=c;
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 11:31:06 +01:00
|
|
|
else for ( ; *s && len > 0; s++, len--) *s = MSVCRT__toupper_l(*s, NULL);
|
2011-03-20 02:17:12 +01:00
|
|
|
if (*s)
|
|
|
|
{
|
|
|
|
*s = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-11 22:13:14 +02:00
|
|
|
/*********************************************************************
|
2019-10-28 13:29:05 +01:00
|
|
|
* _mbsspn_l (MSVCRT.@)
|
2001-07-11 22:13:14 +02:00
|
|
|
*/
|
2019-10-28 13:29:05 +01:00
|
|
|
MSVCRT_size_t CDECL _mbsspn_l(const unsigned char* string,
|
|
|
|
const unsigned char* set, MSVCRT__locale_t locale)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2005-11-21 13:03:18 +01:00
|
|
|
const unsigned char *p, *q;
|
2001-07-11 22:13:14 +02:00
|
|
|
|
2005-11-21 13:03:18 +01:00
|
|
|
for (p = string; *p; p++)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2019-09-02 19:50:24 +02:00
|
|
|
for (q = set; *q; q++)
|
2005-11-21 13:03:18 +01:00
|
|
|
{
|
2019-10-28 13:29:05 +01:00
|
|
|
if (_ismbblead_l(*q, locale))
|
2019-09-02 19:50:29 +02:00
|
|
|
{
|
2019-09-02 19:50:37 +02:00
|
|
|
/* duplicate a bug in native implementation */
|
|
|
|
if (!q[1]) break;
|
|
|
|
|
2019-09-02 19:50:29 +02:00
|
|
|
if (p[0] == q[0] && p[1] == q[1])
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (p[0] == q[0]) break;
|
|
|
|
}
|
2005-11-21 13:03:18 +01:00
|
|
|
}
|
2019-09-02 19:50:24 +02:00
|
|
|
if (!*q) break;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2005-11-21 13:03:18 +01:00
|
|
|
return p - string;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
2019-10-28 13:29:05 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsspn (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbsspn(const unsigned char* string, const unsigned char* set)
|
|
|
|
{
|
|
|
|
return _mbsspn_l(string, set, NULL);
|
|
|
|
}
|
|
|
|
|
2006-12-23 00:24:30 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsspnp (MSVCRT.@)
|
|
|
|
*/
|
2007-08-23 04:14:30 +02:00
|
|
|
unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char* set)
|
2006-12-23 00:24:30 +01:00
|
|
|
{
|
2019-09-02 19:50:29 +02:00
|
|
|
string += _mbsspn( string, set );
|
|
|
|
return *string ? (unsigned char*)string : NULL;
|
2006-12-23 00:24:30 +01:00
|
|
|
}
|
|
|
|
|
2001-07-11 22:13:14 +02:00
|
|
|
/*********************************************************************
|
2019-10-28 13:29:09 +01:00
|
|
|
* _mbscspn_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbscspn_l(const unsigned char* str,
|
|
|
|
const unsigned char* cmp, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
const unsigned char *p, *q;
|
|
|
|
|
|
|
|
for (p = str; *p; p++)
|
|
|
|
{
|
|
|
|
for (q = cmp; *q; q++)
|
|
|
|
{
|
|
|
|
if (_ismbblead_l(*q, locale))
|
|
|
|
{
|
|
|
|
/* duplicate a bug in native implementation */
|
|
|
|
if (!q[1]) return 0;
|
|
|
|
|
|
|
|
if (p[0] == q[0] && p[1] == q[1])
|
|
|
|
return p - str;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
else if (p[0] == q[0])
|
|
|
|
return p - str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbscspn (MSVCRT.@)
|
2001-07-11 22:13:14 +02:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbscspn(const unsigned char* str, const unsigned char* cmp)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2019-10-28 13:29:09 +01:00
|
|
|
return _mbscspn_l(str, cmp, NULL);
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2001-08-09 23:37:19 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsrev (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsrev(unsigned char* str)
|
2001-08-09 23:37:19 +02:00
|
|
|
{
|
|
|
|
int i, len = _mbslen(str);
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char *p, *temp=MSVCRT_malloc(len*2);
|
2001-08-09 23:37:19 +02:00
|
|
|
|
|
|
|
if(!temp)
|
|
|
|
return str;
|
|
|
|
|
|
|
|
/* unpack multibyte string to temp buffer */
|
|
|
|
p=str;
|
|
|
|
for(i=0; i<len; i++)
|
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
if (_ismbblead(*p))
|
2001-08-09 23:37:19 +02:00
|
|
|
{
|
|
|
|
temp[i*2]=*p++;
|
|
|
|
temp[i*2+1]=*p++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp[i*2]=*p++;
|
|
|
|
temp[i*2+1]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* repack it in the reverse order */
|
|
|
|
p=str;
|
|
|
|
for(i=len-1; i>=0; i--)
|
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
if(_ismbblead(temp[i*2]))
|
2001-08-09 23:37:19 +02:00
|
|
|
{
|
|
|
|
*p++=temp[i*2];
|
|
|
|
*p++=temp[i*2+1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*p++=temp[i*2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT_free(temp);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2001-08-11 00:24:54 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbspbrk (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbspbrk(const unsigned char* str, const unsigned char* accept)
|
2001-08-11 00:24:54 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
const unsigned char* p;
|
2001-08-11 00:24:54 +02:00
|
|
|
|
|
|
|
while(*str)
|
|
|
|
{
|
2011-10-12 11:55:51 +02:00
|
|
|
for(p = accept; *p; p += (_ismbblead(*p)?2:1) )
|
2001-08-11 00:24:54 +02:00
|
|
|
{
|
|
|
|
if (*p == *str)
|
2011-10-12 11:55:51 +02:00
|
|
|
if( !_ismbblead(*p) || ( *(p+1) == *(str+1) ) )
|
2001-12-05 23:11:35 +01:00
|
|
|
return (unsigned char*)str;
|
2001-08-11 00:24:54 +02:00
|
|
|
}
|
2011-10-12 11:55:51 +02:00
|
|
|
str += (_ismbblead(*str)?2:1);
|
2001-08-11 00:24:54 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-20 07:59:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions depending on locale codepage
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mblen(MSVCRT.@)
|
|
|
|
* REMARKS
|
|
|
|
* Unlike most of the multibyte string functions this function uses
|
|
|
|
* the locale codepage, not the codepage set by _setmbcp
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
|
|
|
|
{
|
|
|
|
if (str && *str && size)
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
if(get_locinfo()->mb_cur_max == 1)
|
2007-08-20 07:59:52 +02:00
|
|
|
return 1; /* ASCII CP */
|
|
|
|
|
2012-11-29 10:22:27 +01:00
|
|
|
return !MSVCRT_isleadbyte((unsigned char)*str) ? 1 : (size>1 ? 2 : -1);
|
2007-08-20 07:59:52 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:22:27 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* mbrlen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_mbrlen(const char *str, MSVCRT_size_t len, MSVCRT_mbstate_t *state)
|
|
|
|
{
|
|
|
|
MSVCRT_mbstate_t s = (state ? *state : 0);
|
|
|
|
MSVCRT_size_t ret;
|
|
|
|
|
|
|
|
if(!len || !str || !*str)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(get_locinfo()->mb_cur_max == 1) {
|
|
|
|
return 1;
|
|
|
|
}else if(!s && MSVCRT_isleadbyte((unsigned char)*str)) {
|
|
|
|
if(len == 1) {
|
|
|
|
s = (unsigned char)*str;
|
|
|
|
ret = -2;
|
|
|
|
}else {
|
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
}else if(!s) {
|
|
|
|
ret = 1;
|
|
|
|
}else {
|
|
|
|
s = 0;
|
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(state)
|
|
|
|
*state = s;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-06 14:27:22 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbstrlen_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbstrlen_l(const char* str, MSVCRT__locale_t locale)
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
|
2010-05-06 14:27:22 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2010-05-06 14:27:22 +02:00
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
if(locinfo->mb_cur_max > 1) {
|
2011-11-30 14:34:09 +01:00
|
|
|
MSVCRT_size_t len;
|
|
|
|
len = MultiByteToWideChar(locinfo->lc_codepage, MB_ERR_INVALID_CHARS,
|
|
|
|
str, -1, NULL, 0);
|
|
|
|
if (!len) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EILSEQ;
|
|
|
|
return -1;
|
2010-05-06 14:27:22 +02:00
|
|
|
}
|
2011-11-30 14:34:09 +01:00
|
|
|
return len - 1;
|
2010-05-06 14:27:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return strlen(str);
|
|
|
|
}
|
|
|
|
|
2007-08-20 07:59:52 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbstrlen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbstrlen(const char* str)
|
|
|
|
{
|
2010-05-06 14:27:22 +02:00
|
|
|
return _mbstrlen_l(str, NULL);
|
2007-08-20 07:59:52 +02:00
|
|
|
}
|
2010-05-06 14:27:45 +02:00
|
|
|
|
2011-10-12 11:56:13 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbtowc_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_mbtowc_l(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
MSVCRT_wchar_t tmpdst = '\0';
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
|
|
|
|
|
|
|
if(n <= 0 || !str)
|
|
|
|
return 0;
|
2016-05-06 22:09:14 +02:00
|
|
|
|
|
|
|
if(!*str) {
|
|
|
|
if(dst) *dst = 0;
|
2011-10-12 11:56:13 +02:00
|
|
|
return 0;
|
2016-05-06 22:09:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!locinfo->lc_codepage) {
|
|
|
|
if(dst) *dst = (unsigned char)*str;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(n>=2 && MSVCRT__isleadbyte_l((unsigned char)*str, locale)) {
|
|
|
|
if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 2, &tmpdst, 1))
|
|
|
|
return -1;
|
|
|
|
if(dst) *dst = tmpdst;
|
2011-10-12 11:56:13 +02:00
|
|
|
return 2;
|
2016-05-06 22:09:14 +02:00
|
|
|
}
|
|
|
|
if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 1, &tmpdst, 1))
|
|
|
|
return -1;
|
|
|
|
if(dst) *dst = tmpdst;
|
2011-10-12 11:56:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mbtowc(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
return MSVCRT_mbtowc_l(dst, str, n, NULL);
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:23:02 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* mbrtowc(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_mbrtowc(MSVCRT_wchar_t *dst, const char *str,
|
|
|
|
MSVCRT_size_t n, MSVCRT_mbstate_t *state)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadlocinfo locinfo = get_locinfo();
|
|
|
|
MSVCRT_mbstate_t s = (state ? *state : 0);
|
|
|
|
char tmpstr[2];
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
if(dst)
|
|
|
|
*dst = 0;
|
|
|
|
|
|
|
|
if(!n || !str || !*str)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(locinfo->mb_cur_max == 1) {
|
|
|
|
tmpstr[len++] = *str;
|
|
|
|
}else if(!s && MSVCRT_isleadbyte((unsigned char)*str)) {
|
|
|
|
if(n == 1) {
|
|
|
|
s = (unsigned char)*str;
|
|
|
|
len = -2;
|
|
|
|
}else {
|
|
|
|
tmpstr[0] = str[0];
|
|
|
|
tmpstr[1] = str[1];
|
|
|
|
len = 2;
|
|
|
|
}
|
|
|
|
}else if(!s) {
|
|
|
|
tmpstr[len++] = *str;
|
|
|
|
}else {
|
|
|
|
tmpstr[0] = s;
|
|
|
|
tmpstr[1] = *str;
|
|
|
|
len = 2;
|
|
|
|
s = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len > 0) {
|
|
|
|
if(!MultiByteToWideChar(locinfo->lc_codepage, 0, tmpstr, len, dst, dst ? 1 : 0))
|
|
|
|
len = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(state)
|
|
|
|
*state = s;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2010-05-06 14:27:45 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbstowcs_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT__mbstowcs_l(MSVCRT_wchar_t *wcstr, const char *mbstr,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
2011-05-24 17:22:32 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2010-05-22 22:24:40 +02:00
|
|
|
MSVCRT_size_t i, size;
|
2010-05-06 14:27:45 +02:00
|
|
|
|
2014-01-08 12:13:22 +01:00
|
|
|
if(!mbstr) {
|
|
|
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-05-06 14:27:45 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2010-05-06 14:27:45 +02:00
|
|
|
|
2016-06-14 11:57:16 +02:00
|
|
|
if(!locinfo->lc_codepage) {
|
|
|
|
if(!wcstr)
|
|
|
|
return strlen(mbstr);
|
|
|
|
|
|
|
|
for(i=0; i<count; i++) {
|
|
|
|
wcstr[i] = (unsigned char)mbstr[i];
|
|
|
|
if(!wcstr[i]) break;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2010-05-22 22:24:40 +02:00
|
|
|
/* Ignore count parameter */
|
|
|
|
if(!wcstr)
|
2011-05-24 17:22:32 +02:00
|
|
|
return MultiByteToWideChar(locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1;
|
2010-05-06 14:27:45 +02:00
|
|
|
|
2010-05-22 22:24:40 +02:00
|
|
|
for(i=0, size=0; i<count; i++) {
|
|
|
|
if(mbstr[size] == '\0')
|
|
|
|
break;
|
|
|
|
|
2012-11-29 10:23:39 +01:00
|
|
|
size += (MSVCRT__isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1);
|
2010-05-22 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 16:06:39 +02:00
|
|
|
if(size) {
|
|
|
|
size = MultiByteToWideChar(locinfo->lc_codepage, 0,
|
|
|
|
mbstr, size, wcstr, count);
|
|
|
|
if(!size) {
|
|
|
|
if(count) wcstr[0] = '\0';
|
|
|
|
*MSVCRT__errno() = MSVCRT_EILSEQ;
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-14 11:57:07 +02:00
|
|
|
}
|
2010-05-06 14:27:45 +02:00
|
|
|
|
2019-02-28 00:50:34 +01:00
|
|
|
if(size<count)
|
2010-05-22 22:24:40 +02:00
|
|
|
wcstr[size] = '\0';
|
2010-05-06 14:27:45 +02:00
|
|
|
|
2010-05-22 22:24:40 +02:00
|
|
|
return size;
|
2010-05-06 14:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mbstowcs(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_mbstowcs(MSVCRT_wchar_t *wcstr,
|
|
|
|
const char *mbstr, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
return MSVCRT__mbstowcs_l(wcstr, mbstr, count, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbstowcs_s_l(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__mbstowcs_s_l(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr,
|
|
|
|
MSVCRT_size_t size, const char *mbstr,
|
|
|
|
MSVCRT_size_t count, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t conv;
|
2019-11-19 23:06:29 +01:00
|
|
|
int err = 0;
|
2010-05-06 14:27:45 +02:00
|
|
|
|
|
|
|
if(!wcstr && !size) {
|
|
|
|
conv = MSVCRT__mbstowcs_l(NULL, mbstr, 0, locale);
|
|
|
|
if(ret)
|
2011-03-30 15:45:04 +02:00
|
|
|
*ret = conv+1;
|
2010-05-06 14:27:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-26 11:05:32 +02:00
|
|
|
if (!MSVCRT_CHECK_PMT(wcstr != NULL)) return MSVCRT_EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(mbstr != NULL)) {
|
|
|
|
if(size) wcstr[0] = '\0';
|
2010-05-06 14:27:45 +02:00
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-06-06 17:11:09 +02:00
|
|
|
if(count==MSVCRT__TRUNCATE || size<count)
|
2010-05-06 14:27:45 +02:00
|
|
|
conv = size;
|
|
|
|
else
|
|
|
|
conv = count;
|
|
|
|
|
|
|
|
conv = MSVCRT__mbstowcs_l(wcstr, mbstr, conv, locale);
|
|
|
|
if(conv<size)
|
|
|
|
wcstr[conv++] = '\0';
|
2019-11-19 23:06:29 +01:00
|
|
|
else if(conv==size && count==MSVCRT__TRUNCATE && wcstr[conv-1]!='\0') {
|
2010-05-06 14:27:45 +02:00
|
|
|
wcstr[conv-1] = '\0';
|
2019-11-19 23:06:29 +01:00
|
|
|
err = MSVCRT_STRUNCATE;
|
|
|
|
}else if(conv==size && wcstr[conv-1]!='\0') {
|
2012-07-26 11:05:32 +02:00
|
|
|
MSVCRT_INVALID_PMT("wcstr[size] is too small", MSVCRT_ERANGE);
|
2010-05-06 14:27:45 +02:00
|
|
|
if(size)
|
|
|
|
wcstr[0] = '\0';
|
|
|
|
return MSVCRT_ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret)
|
|
|
|
*ret = conv;
|
2019-11-19 23:06:29 +01:00
|
|
|
return err;
|
2010-05-06 14:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mbstowcs_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__mbstowcs_s(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr,
|
|
|
|
MSVCRT_size_t size, const char *mbstr, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
return MSVCRT__mbstowcs_s_l(ret, wcstr, size, mbstr, count, NULL);
|
|
|
|
}
|
2012-11-29 10:23:39 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mbsrtowcs(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL MSVCRT_mbsrtowcs(MSVCRT_wchar_t *wcstr,
|
|
|
|
const char **pmbstr, MSVCRT_size_t count, MSVCRT_mbstate_t *state)
|
|
|
|
{
|
|
|
|
MSVCRT_mbstate_t s = (state ? *state : 0);
|
|
|
|
MSVCRT_wchar_t tmpdst;
|
|
|
|
MSVCRT_size_t ret = 0;
|
2016-05-16 13:29:34 +02:00
|
|
|
const char *p;
|
2012-11-29 10:23:39 +01:00
|
|
|
|
|
|
|
if(!MSVCRT_CHECK_PMT(pmbstr != NULL))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-16 13:29:34 +02:00
|
|
|
p = *pmbstr;
|
2012-11-29 10:23:39 +01:00
|
|
|
while(!wcstr || count>ret) {
|
2016-05-16 13:29:34 +02:00
|
|
|
int ch_len = MSVCRT_mbrtowc(&tmpdst, p, 2, &s);
|
2012-11-29 10:23:39 +01:00
|
|
|
if(wcstr)
|
|
|
|
wcstr[ret] = tmpdst;
|
|
|
|
|
|
|
|
if(ch_len < 0) {
|
|
|
|
return -1;
|
|
|
|
}else if(ch_len == 0) {
|
2016-05-16 13:29:34 +02:00
|
|
|
if(wcstr) *pmbstr = NULL;
|
2012-11-29 10:23:39 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-16 13:29:34 +02:00
|
|
|
p += ch_len;
|
2012-11-29 10:23:39 +01:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
2016-05-16 13:29:34 +02:00
|
|
|
if(wcstr) *pmbstr = p;
|
2012-11-29 10:23:39 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2015-03-16 13:48:46 +01:00
|
|
|
|
2016-05-16 13:29:41 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* mbsrtowcs_s(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_mbsrtowcs_s(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr, MSVCRT_size_t len,
|
|
|
|
const char **mbstr, MSVCRT_size_t count, MSVCRT_mbstate_t *state)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t tmp;
|
|
|
|
|
|
|
|
if(!ret) ret = &tmp;
|
|
|
|
if(!MSVCRT_CHECK_PMT(!!wcstr == !!len)) {
|
|
|
|
*ret = -1;
|
|
|
|
return MSVCRT_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = MSVCRT_mbsrtowcs(wcstr, mbstr, count>len ? len : count, state);
|
|
|
|
if(*ret == -1) {
|
|
|
|
if(wcstr) *wcstr = 0;
|
|
|
|
return *MSVCRT__errno();
|
|
|
|
}
|
|
|
|
(*ret)++;
|
|
|
|
if(*ret > len) {
|
|
|
|
/* no place for terminating '\0' */
|
|
|
|
if(wcstr) *wcstr = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(wcstr) wcstr[(*ret)-1] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:48:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbctohira (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Converts a sjis katakana character to hiragana.
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _mbctohira(unsigned int c)
|
|
|
|
{
|
|
|
|
if(_ismbckata(c) && c <= 0x8393)
|
|
|
|
return (c - 0x8340 - (c >= 0x837f ? 1 : 0)) + 0x829f;
|
|
|
|
return c;
|
|
|
|
}
|
2015-03-16 13:48:48 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbctokata (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Converts a sjis hiragana character to katakana.
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _mbctokata(unsigned int c)
|
|
|
|
{
|
|
|
|
if(_ismbchira(c))
|
|
|
|
return (c - 0x829f) + 0x8340 + (c >= 0x82de ? 1 : 0);
|
|
|
|
return c;
|
|
|
|
}
|
2017-08-08 15:44:41 +02:00
|
|
|
|
2019-02-14 14:35:32 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcl0_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbcl0_l(unsigned int c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
if(mbcinfo->mbcodepage == 932)
|
|
|
|
{
|
|
|
|
/* JIS non-Kanji */
|
2019-02-15 12:24:37 +01:00
|
|
|
return _ismbclegal_l(c, locale) && c >= 0x8140 && c <= 0x889e;
|
2019-02-14 14:35:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-08 15:44:41 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcl0 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbcl0(unsigned int c)
|
|
|
|
{
|
2019-02-14 14:35:32 +01:00
|
|
|
return _ismbcl0_l(c, NULL);
|
2017-08-08 15:44:41 +02:00
|
|
|
}
|
2019-02-14 14:35:40 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcl1_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbcl1_l(unsigned int c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
if(mbcinfo->mbcodepage == 932)
|
|
|
|
{
|
|
|
|
/* JIS level-1 */
|
2019-02-15 12:24:37 +01:00
|
|
|
return _ismbclegal_l(c, locale) && c >= 0x889f && c <= 0x9872;
|
2019-02-14 14:35:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-02-14 14:35:45 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcl1 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbcl1(unsigned int c)
|
|
|
|
{
|
|
|
|
return _ismbcl1_l(c, NULL);
|
|
|
|
}
|
2019-02-15 12:24:48 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcl2_l (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbcl2_l(unsigned int c, MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
MSVCRT_pthreadmbcinfo mbcinfo;
|
|
|
|
|
|
|
|
if(!locale)
|
|
|
|
mbcinfo = get_mbcinfo();
|
|
|
|
else
|
|
|
|
mbcinfo = locale->mbcinfo;
|
|
|
|
|
|
|
|
if(mbcinfo->mbcodepage == 932)
|
|
|
|
{
|
|
|
|
/* JIS level-2 */
|
|
|
|
return _ismbclegal_l(c, locale) && c >= 0x989f && c <= 0xeaa4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-02-15 12:24:57 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcl2 (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ismbcl2(unsigned int c)
|
|
|
|
{
|
|
|
|
return _ismbcl2_l(c, NULL);
|
|
|
|
}
|