- Synchronize up to trunk's revision r57864.
[reactos.git] / lib / sdk / crt / mbstring / mbsncpy.c
index 407a820..4780e27 100644 (file)
 #include <precomp.h>
 #include <mbstring.h>
 
-extern int g_mbcp_is_multibyte;
-
-/*
- * @implemented
+/*********************************************************************
+ *             _mbsncpy(MSVCRT.@)
+ * 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
  */
-unsigned char* _mbsncpy(unsigned char *dst, const unsigned char *src, size_t n)
+unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, size_t n)
 {
   unsigned char* ret = dst;
   if(!n)
     return dst;
-  if (g_mbcp_is_multibyte)
+  if (get_mbcinfo()->ismbcodepage)
   {
     while (*src && n)
     {
@@ -55,48 +56,12 @@ unsigned char* _mbsncpy(unsigned char *dst, const unsigned char *src, size_t n)
   return ret;
 }
 
-
-/*
- * The _mbsnbcpy function copies count bytes from src to dest. If src is shorter
- * than dest, the string is padded with null characters. If dest is less than or
- * equal to count it is not terminated with a null character.
- *
- * @implemented
- */
-unsigned char * _mbsnbcpy(unsigned char *dst, const unsigned char *src, size_t n)
-{
-  unsigned char* ret = dst;
-  if(!n)
-    return dst;
-  if(g_mbcp_is_multibyte)
-  {
-    int is_lead = 0;
-    while (*src && n)
-    {
-      is_lead = (!is_lead && _ismbblead(*src));
-      n--;
-      *dst++ = *src++;
-    }
-
-    if (is_lead) /* if string ends with a lead, remove it */
-      *(dst - 1) = 0;
-  }
-  else
-  {
-    while (n)
-    {
-        n--;
-        if (!(*dst++ = *src++)) break;
-    }
-  }
-  while (n--) *dst++ = 0;
-  return ret;
-}
-
-/*
+/*********************************************************************
+ *              _mbsnbcpy_s(MSVCRT.@)
+ * REMARKS
  * 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;
@@ -111,7 +76,7 @@ int CDECL _mbsnbcpy_s(unsigned char* dst, size_t size, const unsigned char* src,
     if(!n)
         return 0;
 
-    if(g_mbcp_is_multibyte)
+    if(get_mbcinfo()->ismbcodepage)
     {
         int is_lead = 0;
         while (*src && n)
@@ -155,3 +120,40 @@ int CDECL _mbsnbcpy_s(unsigned char* dst, size_t size, const unsigned char* src,
 
     return 0;
 }
+
+/*********************************************************************
+ *              _mbsnbcpy(MSVCRT.@)
+ * REMARKS
+ *  Like strncpy this function doesn't enforce the string to be
+ *  NUL-terminated
+ */
+unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, size_t n)
+{
+  unsigned char* ret = dst;
+  if(!n)
+    return dst;
+  if(get_mbcinfo()->ismbcodepage)
+  {
+    int is_lead = 0;
+    while (*src && n)
+    {
+      is_lead = (!is_lead && _ismbblead(*src));
+      n--;
+      *dst++ = *src++;
+    }
+
+    if (is_lead) /* if string ends with a lead, remove it */
+       *(dst - 1) = 0;
+  }
+  else
+  {
+    while (n)
+    {
+        n--;
+        if (!(*dst++ = *src++)) break;
+    }
+  }
+  while (n--) *dst++ = 0;
+  return ret;
+}
+