Author: cwittich
Date: Thu Jan 22 08:41:57 2009
New Revision: 39014
URL:
http://svn.reactos.org/svn/reactos?rev=39014&view=rev
Log:
add _mbsnbcpy_s to msvcrt (imported from wine)
Modified:
trunk/reactos/dll/win32/msvcrt/msvcrt.def
trunk/reactos/include/crt/mbstring.h
trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c
Modified: trunk/reactos/dll/win32/msvcrt/msvcrt.def
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msvcrt/msvcrt.de…
==============================================================================
--- trunk/reactos/dll/win32/msvcrt/msvcrt.def [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msvcrt/msvcrt.def [iso-8859-1] Thu Jan 22 08:41:57 2009
@@ -847,4 +847,6 @@
wprintf @841
wscanf @842
+ _mbsnbcpy_s
+
_swprintf=swprintf
Modified: trunk/reactos/include/crt/mbstring.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/mbstring.h?rev…
==============================================================================
--- trunk/reactos/include/crt/mbstring.h [iso-8859-1] (original)
+++ trunk/reactos/include/crt/mbstring.h [iso-8859-1] Thu Jan 22 08:41:57 2009
@@ -75,6 +75,7 @@
_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);
Modified: trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbsnc…
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbsncpy.c [iso-8859-1] Thu Jan 22 08:41:57 2009
@@ -10,6 +10,7 @@
*
*/
+#include <precomp.h>
#include <mbstring.h>
extern int g_mbcp_is_multibyte;
@@ -91,3 +92,66 @@
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;
+}