[CRT]
[reactos.git] / lib / sdk / crt / string / wcs.c
index 855ba75..aca8147 100644 (file)
 #undef vprintf
 #undef vwprintf
 
+#ifdef _MSC_VER
+#pragma function(_wcsset)
+#endif
+
 #ifndef _LIBCNT_
 /*********************************************************************
  *             _wcsdup (MSVCRT.@)
@@ -109,6 +113,35 @@ wchar_t* CDECL _wcsset( wchar_t* str, wchar_t c )
   return ret;
 }
 
+/******************************************************************
+ *             _wcsupr_s (MSVCRT.@)
+ *
+ */
+INT CDECL _wcsupr_s( wchar_t* str, size_t n )
+{
+  wchar_t* ptr = str;
+
+  if (!str || !n)
+  {
+    if (str) *str = '\0';
+    __set_errno(EINVAL);
+    return EINVAL;
+  }
+
+  while (n--)
+  {
+    if (!*ptr) return 0;
+    *ptr = toupperW(*ptr);
+    ptr++;
+  }
+
+  /* MSDN claims that the function should return and set errno to
+   * ERANGE, which doesn't seem to be true based on the tests. */
+  *str = '\0';
+  __set_errno(EINVAL);
+  return EINVAL;
+}
+
 /*********************************************************************
  *             wcstod (MSVCRT.@)
  */
@@ -430,7 +463,7 @@ static void pf_rebuild_format_string( char *p, pf_flags *flags )
 
 /* pf_integer_conv:  prints x to buf, including alternate formats and
    additional precision digits, but not field characters or the sign */
-static void pf_integer_conv( char *buf, int buf_len, pf_flags *flags,
+static void pf_integer_conv( char *buf, unsigned int buf_len, pf_flags *flags,
                              LONGLONG x )
 {
     unsigned int base;
@@ -679,8 +712,8 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, va_list valist )
                * Includes extra bytes: 1 byte for null, 1 byte for sign,
                  4 bytes for exponent, 2 bytes for alternate formats, 1 byte 
                  for a decimal, and 1 byte for an additional float digit. */
-            int x_len = ((flags.FieldLength > flags.Precision) ? 
-                        flags.FieldLength : flags.Precision) + 10;
+            unsigned x_len = ((flags.FieldLength > flags.Precision) ? 
+                              flags.FieldLength : flags.Precision) + 10;
 
             if( x_len >= sizeof number)
                 x = HeapAlloc( GetProcessHeap(), 0, x_len );
@@ -702,8 +735,8 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, va_list valist )
                * Includes extra bytes: 1 byte for null, 1 byte for sign,
                  4 bytes for exponent, 2 bytes for alternate formats, 1 byte 
                  for a decimal, and 1 byte for an additional float digit. */
-            int x_len = ((flags.FieldLength > flags.Precision) ? 
-                        flags.FieldLength : flags.Precision) + 10;
+            unsigned x_len = ((flags.FieldLength > flags.Precision) ? 
+                              flags.FieldLength : flags.Precision) + 10;
 
             if( x_len >= sizeof number)
                 x = HeapAlloc( GetProcessHeap(), 0, x_len );
@@ -1106,6 +1139,8 @@ INT CDECL iswxdigit( wchar_t wc )
     return isxdigitW( wc );
 }
 
+#endif
+
 /*********************************************************************
  *             wcscpy_s (MSVCRT.@)
  */
@@ -1130,11 +1165,40 @@ INT CDECL wcscpy_s( wchar_t* wcDest, size_t numElement, const  wchar_t *wcSrc)
         return ERANGE;
     }
 
-    if(size > numElement)
-        size = numElement;
+    memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
+
+    return 0;
+}
+
+/******************************************************************
+ *             wcsncpy_s (MSVCRT.@)
+ */
+INT CDECL wcsncpy_s( wchar_t* wcDest, size_t numElement, const wchar_t *wcSrc,
+                            size_t count )
+{
+    size_t size = 0;
+
+    if (!wcDest || !numElement)
+        return EINVAL;
+
+    wcDest[0] = 0;
+
+    if (!wcSrc)
+    {
+        return EINVAL;
+    }
+
+    size = min(strlenW(wcSrc), count);
+
+    if (size >= numElement)
+    {
+        return ERANGE;
+    }
 
     memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
+    wcDest[size] = '\0';
 
     return 0;
 }
-#endif
+
+