mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 16:45:50 +00:00
add _mbsnbcpy_s to msvcrt (imported from wine)
svn path=/trunk/; revision=39014
This commit is contained in:
parent
bcccb1d084
commit
969279fc8a
3 changed files with 67 additions and 0 deletions
|
@ -847,4 +847,6 @@ EXPORTS
|
|||
wprintf @841
|
||||
wscanf @842
|
||||
|
||||
_mbsnbcpy_s
|
||||
|
||||
_swprintf=swprintf
|
||||
|
|
|
@ -75,6 +75,7 @@ extern "C" {
|
|||
_CRTIMP size_t __cdecl _mbsnbcnt(const unsigned char *_Str,size_t _MaxCount);
|
||||
_CRTIMP size_t __cdecl _mbsnbcnt_l(const unsigned char *_Str,size_t _MaxCount,_locale_t _Locale);
|
||||
_CRTIMP unsigned char *__cdecl _mbsnbcpy(unsigned char *_Dest,const unsigned char *_Source,size_t _Count);
|
||||
_CRTIMP int __cdecl _mbsnbcpy_s(unsigned char* dst, size_t size, const unsigned char* src, size_t n);
|
||||
_CRTIMP unsigned char *__cdecl _mbsnbcpy_l(unsigned char *_Dest,const unsigned char *_Source,size_t _Count,_locale_t _Locale);
|
||||
_CRTIMP int __cdecl _mbsnbicmp(const unsigned char *_Str1,const unsigned char *_Str2,size_t _MaxCount);
|
||||
_CRTIMP int __cdecl _mbsnbicmp_l(const unsigned char *_Str1,const unsigned char *_Str2,size_t _MaxCount,_locale_t _Locale);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
#include <mbstring.h>
|
||||
|
||||
extern int g_mbcp_is_multibyte;
|
||||
|
@ -91,3 +92,66 @@ unsigned char * _mbsnbcpy(unsigned char *dst, const unsigned char *src, size_t n
|
|||
while (n--) *dst++ = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unlike _mbsnbcpy this function does not pad the rest of the dest
|
||||
* string with 0
|
||||
*/
|
||||
int CDECL _mbsnbcpy_s(unsigned char* dst, size_t size, const unsigned char* src, size_t n)
|
||||
{
|
||||
size_t pos = 0;
|
||||
|
||||
if(!dst || size == 0)
|
||||
return EINVAL;
|
||||
if(!src)
|
||||
{
|
||||
dst[0] = '\0';
|
||||
return EINVAL;
|
||||
}
|
||||
if(!n)
|
||||
return 0;
|
||||
|
||||
if(g_mbcp_is_multibyte)
|
||||
{
|
||||
int is_lead = 0;
|
||||
while (*src && n)
|
||||
{
|
||||
if(pos == size)
|
||||
{
|
||||
dst[0] = '\0';
|
||||
return ERANGE;
|
||||
}
|
||||
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';
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
if(!(*src)) break;
|
||||
dst[pos++] = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
if(pos < size)
|
||||
dst[pos] = '\0';
|
||||
else
|
||||
{
|
||||
dst[0] = '\0';
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue