Return correct size. This fixes bug 756
[reactos.git] / reactos / lib / rtl / unicode.c
index 1227527..0acf7bc 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #define __NTDRIVER__
-#include "rtl.h"
+#include <rtl.h>
 
 #define NDEBUG
 #include <debug.h>
 
 /* GLOBALS *******************************************************************/
 
-#define TAG_USTR  TAG('U', 'S', 'T', 'R')
-#define TAG_ASTR  TAG('A', 'S', 'T', 'R')
-#define TAG_OSTR  TAG('O', 'S', 'T', 'R')
-
-
 extern BOOLEAN NlsMbCodePageTag;
 extern BOOLEAN NlsMbOemCodePageTag;
 
@@ -71,15 +66,17 @@ RtlAnsiCharToUnicodeChar (IN CHAR AnsiChar)
  */
 ULONG
 STDCALL
-RtlAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
+RtlxAnsiStringToUnicodeSize(IN PCANSI_STRING AnsiString)
 {
-   ULONG Size;
+    ULONG Size;
 
-   RtlMultiByteToUnicodeSize(&Size,
-                             AnsiString->Buffer,
-                             AnsiString->Length);
+    /* Convert from Mb String to Unicode Size */
+    RtlMultiByteToUnicodeSize(&Size,
+                              AnsiString->Buffer,
+                              AnsiString->Length);
 
-   return(Size);
+    /* Return the size plus the null-char */
+    return(Size + sizeof(WCHAR));
 }
 
 
@@ -130,7 +127,7 @@ NTSTATUS
 STDCALL
 RtlAppendUnicodeStringToString(
    IN OUT PUNICODE_STRING Destination,
-   IN PUNICODE_STRING Source)
+   IN PCUNICODE_STRING Source)
 {
 
    if ((Source->Length + Destination->Length) > Destination->MaximumLength)
@@ -223,7 +220,7 @@ RtlCharToInteger(
        } else {
            digit = -1;
        } /* if */
-       if (digit < 0 || digit >= base) {
+       if (digit < 0 || digit >= (int)base) {
            *value = bMinus ? -RunningTotal : RunningTotal;
            return STATUS_SUCCESS;
        } /* if */
@@ -242,47 +239,28 @@ RtlCharToInteger(
 LONG
 STDCALL
 RtlCompareString(
-   IN PSTRING String1,
-   IN PSTRING String2,
+   IN PSTRING s1,
+   IN PSTRING s2,
    IN BOOLEAN CaseInsensitive)
 {
-   ULONG len1, len2;
-   PCHAR s1, s2;
-   CHAR  c1, c2;
+   unsigned int len;
+   LONG ret = 0;
+   LPCSTR p1, p2;
 
-   if (String1 && String2)
-   {
-      len1 = String1->Length;
-      len2 = String2->Length;
-      s1 = String1->Buffer;
-      s2 = String2->Buffer;
+   len = min(s1->Length, s2->Length);
+   p1 = s1->Buffer;
+   p2 = s2->Buffer;
 
-      if (s1 && s2)
-      {
-         if (CaseInsensitive)
-         {
-            for(;;)
-            {
-               c1 = len1-- ? RtlUpperChar (*s1++) : 0;
-               c2 = len2-- ? RtlUpperChar (*s2++) : 0;
-               if (!c1 || !c2 || c1 != c2)
-                  return c1 - c2;
-            }
-         }
-         else
-         {
-            for(;;)
-            {
-               c1 = len1-- ? *s1++ : 0;
-               c2 = len2-- ? *s2++ : 0;
-               if (!c1 || !c2 || c1 != c2)
-                  return c1 - c2;
-            }
-         }
-      }
+   if (CaseInsensitive)
+   {
+     while (!ret && len--) ret = RtlUpperChar(*p1++) - RtlUpperChar(*p2++);
    }
-
-   return 0;
+   else
+   {
+     while (!ret && len--) ret = *p1++ - *p2++;
+   }
+   if (!ret) ret = s1->Length - s2->Length;
+   return ret;
 }
 
 
@@ -295,40 +273,12 @@ RtlCompareString(
 BOOLEAN
 STDCALL
 RtlEqualString(
-   IN PSTRING String1,
-   IN PSTRING String2,
+   IN PSTRING s1,
+   IN PSTRING s2,
    IN BOOLEAN CaseInsensitive)
 {
-   ULONG i;
-   CHAR c1, c2;
-   PCHAR p1, p2;
-
-   if (String1->Length != String2->Length)
-      return FALSE;
-
-   p1 = String1->Buffer;
-   p2 = String2->Buffer;
-   for (i = 0; i < String1->Length; i++)
-   {
-      if (CaseInsensitive == TRUE)
-      {
-         c1 = RtlUpperChar (*p1);
-         c2 = RtlUpperChar (*p2);
-      }
-      else
-      {
-         c1 = *p1;
-         c2 = *p2;
-      }
-
-      if (c1 != c2)
-         return FALSE;
-
-      p1++;
-      p2++;
-   }
-
-   return TRUE;
+   if (s1->Length != s2->Length) return FALSE;
+   return !RtlCompareString(s1, s2, CaseInsensitive );
 }
 
 
@@ -341,41 +291,12 @@ RtlEqualString(
 BOOLEAN
 STDCALL
 RtlEqualUnicodeString(
-   IN CONST UNICODE_STRING *String1,
-   IN CONST UNICODE_STRING *String2,
+   IN CONST UNICODE_STRING *s1,
+   IN CONST UNICODE_STRING *s2,
    IN BOOLEAN  CaseInsensitive)
 {
-   ULONG i;
-   WCHAR wc1, wc2;
-   PWCHAR pw1, pw2;
-
-   if (String1->Length != String2->Length)
-      return FALSE;
-
-   pw1 = String1->Buffer;
-   pw2 = String2->Buffer;
-
-   for (i = 0; i < String1->Length / sizeof(WCHAR); i++)
-   {
-      if (CaseInsensitive == TRUE)
-      {
-         wc1 = RtlUpcaseUnicodeChar (*pw1);
-         wc2 = RtlUpcaseUnicodeChar (*pw2);
-      }
-      else
-      {
-         wc1 = *pw1;
-         wc2 = *pw2;
-      }
-
-      if (wc1 != wc2)
-         return FALSE;
-
-      pw1++;
-      pw2++;
-   }
-
-   return TRUE;
+   if (s1->Length != s2->Length) return FALSE;
+   return !RtlCompareUnicodeString((PUNICODE_STRING)s1, (PUNICODE_STRING)s2, CaseInsensitive );
 }
 
 
@@ -386,14 +307,14 @@ VOID
 STDCALL
 RtlFreeAnsiString(IN PANSI_STRING AnsiString)
 {
-   if (AnsiString->Buffer == NULL)
-      return;
-
-   ExFreePoolWithTag(AnsiString->Buffer, TAG_ASTR);
+   if (AnsiString->Buffer != NULL)
+   {
+      RtlpFreeStringMemory(AnsiString->Buffer, TAG_ASTR);
 
-   AnsiString->Buffer = NULL;
-   AnsiString->Length = 0;
-   AnsiString->MaximumLength = 0;
+      AnsiString->Buffer = NULL;
+      AnsiString->Length = 0;
+      AnsiString->MaximumLength = 0;
+   }
 }
 
 
@@ -404,14 +325,14 @@ VOID
 STDCALL
 RtlFreeOemString(IN POEM_STRING OemString)
 {
-   if (OemString->Buffer == NULL)
-      return;
-
-   ExFreePoolWithTag(OemString->Buffer, TAG_OSTR);
+   if (OemString->Buffer != NULL)
+   {
+      RtlpFreeStringMemory(OemString->Buffer, TAG_OSTR);
 
-   OemString->Buffer = NULL;
-   OemString->Length = 0;
-   OemString->MaximumLength = 0;
+      OemString->Buffer = NULL;
+      OemString->Length = 0;
+      OemString->MaximumLength = 0;
+   }
 }
 
 
@@ -422,14 +343,14 @@ VOID
 STDCALL
 RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
 {
-   if (UnicodeString->Buffer == NULL)
-      return;
-
-   ExFreePoolWithTag(UnicodeString->Buffer, TAG_USTR);
+   if (UnicodeString->Buffer != NULL)
+   {
+      RtlpFreeStringMemory(UnicodeString->Buffer, TAG_USTR);
 
-   UnicodeString->Buffer = NULL;
-   UnicodeString->Length = 0;
-   UnicodeString->MaximumLength = 0;
+      UnicodeString->Buffer = NULL;
+      UnicodeString->Length = 0;
+      UnicodeString->MaximumLength = 0;
+   }
 }
 
 /*
@@ -516,7 +437,7 @@ RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString,
 {
    ULONG DestSize;
 
-   DPRINT("RtlInitUnicodeString(DestinationString %x, SourceString %x)\n",
+   DPRINT("RtlInitUnicodeString(DestinationString 0x%p, SourceString 0x%p)\n",
           DestinationString,
           SourceString);
 
@@ -608,7 +529,7 @@ RtlIntegerToChar(
       tp++;
    }
 
-   if (tp - temp >= Length)
+   if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
    {
       return STATUS_BUFFER_TOO_SMALL;
    }
@@ -663,7 +584,7 @@ RtlIntegerToUnicode(
       tp++;
    }
 
-   if (tp - temp >= Length)
+   if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
    {
       return STATUS_BUFFER_TOO_SMALL;
    }
@@ -696,16 +617,16 @@ RtlIntegerToUnicodeString(
                               Base,
                               sizeof(Buffer),
                               Buffer);
-   if (!NT_SUCCESS(Status))
-      return Status;
-
-   AnsiString.Buffer = Buffer;
-   AnsiString.Length = strlen (Buffer);
-   AnsiString.MaximumLength = sizeof(Buffer);
+   if (NT_SUCCESS(Status))
+   {
+      AnsiString.Buffer = Buffer;
+      AnsiString.Length = strlen (Buffer);
+      AnsiString.MaximumLength = sizeof(Buffer);
 
-   Status = RtlAnsiStringToUnicodeString (String,
-                                          &AnsiString,
-                                          FALSE);
+      Status = RtlAnsiStringToUnicodeString (String,
+                                             &AnsiString,
+                                             FALSE);
+   }
 
    return Status;
 }
@@ -733,16 +654,16 @@ RtlInt64ToUnicodeString (
                                    Base,
                                    sizeof(Buffer),
                                    Buffer);
-   if (!NT_SUCCESS(Status))
-      return Status;
-
-   AnsiString.Buffer = Buffer;
-   AnsiString.Length = strlen (Buffer);
-   AnsiString.MaximumLength = sizeof(Buffer);
+   if (NT_SUCCESS(Status))
+   {
+      AnsiString.Buffer = Buffer;
+      AnsiString.Length = strlen (Buffer);
+      AnsiString.MaximumLength = sizeof(Buffer);
 
-   Status = RtlAnsiStringToUnicodeString (String,
-                                          &AnsiString,
-                                          FALSE);
+      Status = RtlAnsiStringToUnicodeString (String,
+                                             &AnsiString,
+                                             FALSE);
+   }
 
    return Status;
 }
@@ -805,8 +726,8 @@ RtlPrefixString(
 BOOLEAN
 STDCALL
 RtlPrefixUnicodeString(
-   PUNICODE_STRING String1,
-   PUNICODE_STRING String2,
+   PCUNICODE_STRING String1,
+   PCUNICODE_STRING String2,
    BOOLEAN  CaseInsensitive)
 {
    PWCHAR pc1;
@@ -873,7 +794,7 @@ RtlPrefixUnicodeString(
 NTSTATUS
 STDCALL
 RtlUnicodeStringToInteger(
-    PUNICODE_STRING str, /* [I] Unicode string to be converted */
+    PCUNICODE_STRING str, /* [I] Unicode string to be converted */
     ULONG base,                /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
     PULONG value)              /* [O] Destination for the converted value */
 {
@@ -881,44 +802,49 @@ RtlUnicodeStringToInteger(
     USHORT CharsRemaining = str->Length / sizeof(WCHAR);
     WCHAR wchCurrent;
     int digit;
+    ULONG newbase = 0;
     ULONG RunningTotal = 0;
     char bMinus = 0;
 
-    while (CharsRemaining >= 1 && *lpwstr <= ' ') {
+    while (CharsRemaining >= 1 && *lpwstr <= L' ') {
        lpwstr++;
        CharsRemaining--;
     } /* while */
 
     if (CharsRemaining >= 1) {
-       if (*lpwstr == '+') {
+       if (*lpwstr == L'+') {
            lpwstr++;
            CharsRemaining--;
-       } else if (*lpwstr == '-') {
+       } else if (*lpwstr == L'-') {
            bMinus = 1;
            lpwstr++;
            CharsRemaining--;
        } /* if */
     } /* if */
 
-    if (base == 0) {
-       base = 10;
-       if (CharsRemaining >= 2 && lpwstr[0] == '0') {
-           if (lpwstr[1] == 'b') {
-               lpwstr += 2;
-               CharsRemaining -= 2;
-               base = 2;
-           } else if (lpwstr[1] == 'o') {
-               lpwstr += 2;
-               CharsRemaining -= 2;
-               base = 8;
-           } else if (lpwstr[1] == 'x') {
-               lpwstr += 2;
-               CharsRemaining -= 2;
-               base = 16;
-           } /* if */
+    if (CharsRemaining >= 2 && lpwstr[0] == L'0') {
+        if (lpwstr[1] == L'b' || lpwstr[1] == L'B') {
+           lpwstr += 2;
+           CharsRemaining -= 2;
+           newbase = 2;
+       } else if (lpwstr[1] == L'o' || lpwstr[1] == L'O') {
+           lpwstr += 2;
+           CharsRemaining -= 2;
+           newbase = 8;
+        } else if (lpwstr[1] == L'x' || lpwstr[1] == L'X') {
+           lpwstr += 2;
+           CharsRemaining -= 2;
+           newbase = 16;
        } /* if */
-    } else if (base != 2 && base != 8 && base != 10 && base != 16) {
+    }
+    if (base == 0 && newbase == 0) {
+        base = 10;
+    } else if (base == 0 && newbase != 0) {
+        base = newbase;
+    } else if ((newbase != 0 && base != newbase) ||
+               (base != 2 && base != 8 && base != 10 && base != 16)) {
        return STATUS_INVALID_PARAMETER;
+
     } /* if */
 
     if (value == NULL) {
@@ -927,16 +853,16 @@ RtlUnicodeStringToInteger(
 
     while (CharsRemaining >= 1) {
        wchCurrent = *lpwstr;
-       if (wchCurrent >= '0' && wchCurrent <= '9') {
-           digit = wchCurrent - '0';
-       } else if (wchCurrent >= 'A' && wchCurrent <= 'Z') {
-           digit = wchCurrent - 'A' + 10;
-       } else if (wchCurrent >= 'a' && wchCurrent <= 'z') {
-           digit = wchCurrent - 'a' + 10;
+       if (wchCurrent >= L'0' && wchCurrent <= L'9') {
+           digit = wchCurrent - L'0';
+       } else if (wchCurrent >= L'A' && wchCurrent <= L'Z') {
+           digit = wchCurrent - L'A' + 10;
+       } else if (wchCurrent >= L'a' && wchCurrent <= L'z') {
+           digit = wchCurrent - L'a' + 10;
        } else {
            digit = -1;
        } /* if */
-       if (digit < 0 || digit >= base) {
+       if (digit < 0 || digit >= (int)base) {
            *value = bMinus ? -RunningTotal : RunningTotal;
            return STATUS_SUCCESS;
        } /* if */
@@ -959,48 +885,43 @@ RtlUnicodeStringToInteger(
  */
 ULONG
 STDCALL
-RtlUnicodeStringToOemSize(
-   IN PUNICODE_STRING UnicodeString)
+RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString)
 {
-   ULONG Size;
+    ULONG Size;
 
-   RtlUnicodeToMultiByteSize (&Size,
+    /* Convert the Unicode String to Mb Size */
+    RtlUnicodeToMultiByteSize(&Size,
                               UnicodeString->Buffer,
                               UnicodeString->Length);
 
-   return Size+1; //NB: incl. nullterm
+    /* Return the size + the null char */
+    return (Size + sizeof(CHAR));
 }
 
 /*
- * private
+ * @implemented
  *
+
  * NOTES
  *  This function always writes a terminating '\0'.
  *  It performs a partial copy if ansi is too small.
  */
 NTSTATUS
-FASTCALL
-RtlpUnicodeStringToAnsiString(
+STDCALL
+RtlUnicodeStringToAnsiString(
    IN OUT PANSI_STRING AnsiDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN PCUNICODE_STRING UniSource,
+   IN BOOLEAN AllocateDestinationString)
 {
    NTSTATUS Status = STATUS_SUCCESS;
-   ULONG Length; //including nullterm
-
-   if (NlsMbCodePageTag == TRUE)
-   {
-      Length = RtlUnicodeStringToAnsiSize(UniSource);
-   }
-   else
-      Length = (UniSource->Length / sizeof(WCHAR)) + sizeof(CHAR);
+   ULONG Length; /* including nullterm */
 
+   Length = RtlUnicodeStringToAnsiSize(UniSource);
    AnsiDest->Length = Length - sizeof(CHAR);
 
    if (AllocateDestinationString)
    {
-      AnsiDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_ASTR);
+      AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
       if (AnsiDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -1012,7 +933,7 @@ RtlpUnicodeStringToAnsiString(
    }
    else if (Length > AnsiDest->MaximumLength)
    {
-      //make room for nullterm
+      /* make room for nullterm */
       AnsiDest->Length = AnsiDest->MaximumLength - sizeof(CHAR);
    }
 
@@ -1024,7 +945,7 @@ RtlpUnicodeStringToAnsiString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(AnsiDest->Buffer, TAG_ASTR);
+      RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
       return Status;
    }
 
@@ -1032,50 +953,25 @@ RtlpUnicodeStringToAnsiString(
    return Status;
 }
 
-/*
- * @implemented
- *
-
- * NOTES
- *  See RtlpUnicodeStringToAnsiString
- */
-NTSTATUS
-STDCALL
-RtlUnicodeStringToAnsiString(
-   IN OUT PANSI_STRING AnsiDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString)
-{
-   return RtlpUnicodeStringToAnsiString(
-             AnsiDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
 
 /*
- * private
+ * @implemented
  *
  * NOTES
  *  This function always writes a terminating '\0'.
  *  Does NOT perform a partial copy if unicode is too small!
  */
 NTSTATUS
-FASTCALL
-RtlpOemStringToUnicodeString(
+STDCALL
+RtlOemStringToUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
-   IN POEM_STRING OemSource,
-   IN BOOLEAN AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN PCOEM_STRING OemSource,
+   IN BOOLEAN AllocateDestinationString)
 {
    NTSTATUS Status;
-   ULONG Length; //including nullterm
-
-   if (NlsMbOemCodePageTag == TRUE)
-      Length = RtlOemStringToUnicodeSize(OemSource);
-   else
-      Length = (OemSource->Length * sizeof(WCHAR)) + sizeof(WCHAR);
+   ULONG Length; /* including nullterm */
 
+   Length = RtlOemStringToUnicodeSize(OemSource);
    if (Length > 0xffff)
       return STATUS_INVALID_PARAMETER_2;
 
@@ -1083,7 +979,7 @@ RtlpOemStringToUnicodeString(
 
    if (AllocateDestinationString)
    {
-      UniDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_USTR);
+      UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
       if (UniDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -1095,7 +991,7 @@ RtlpOemStringToUnicodeString(
       return STATUS_BUFFER_TOO_SMALL;
    }
 
-   //FIXME: Do we need this????? -Gunnar
+   /* FIXME: Do we need this????? -Gunnar */
    RtlZeroMemory (UniDest->Buffer,
                   UniDest->Length);
 
@@ -1107,7 +1003,7 @@ RtlpOemStringToUnicodeString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(UniDest->Buffer, TAG_USTR);
+      RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
       return Status;
    }
 
@@ -1120,44 +1016,19 @@ RtlpOemStringToUnicodeString(
  * @implemented
  *
  * NOTES
- *  See RtlpOemStringToUnicodeString
- */
-NTSTATUS
-STDCALL
-RtlOemStringToUnicodeString(
-   IN OUT PUNICODE_STRING UniDest,
-   IN POEM_STRING OemSource,
-   IN BOOLEAN AllocateDestinationString)
-{
-   return RtlpOemStringToUnicodeString(
-             UniDest,
-             OemSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
-/*
- * private
- *
- * NOTES
  *   This function always '\0' terminates the string returned.
  */
 NTSTATUS
-FASTCALL
-RtlpUnicodeStringToOemString(
+STDCALL
+RtlUnicodeStringToOemString(
    IN OUT POEM_STRING OemDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN PCUNICODE_STRING UniSource,
+   IN BOOLEAN  AllocateDestinationString)
 {
    NTSTATUS Status = STATUS_SUCCESS;
    ULONG Length; //including nullterm
 
-   if (NlsMbOemCodePageTag == TRUE)
-      Length = RtlUnicodeStringToAnsiSize (UniSource);
-   else
-      Length = (UniSource->Length / sizeof(WCHAR)) + sizeof(CHAR);
-
+   Length = RtlUnicodeStringToAnsiSize(UniSource);
    if (Length > 0x0000FFFF)
       return STATUS_INVALID_PARAMETER_2;
 
@@ -1165,7 +1036,7 @@ RtlpUnicodeStringToOemString(
 
    if (AllocateDestinationString)
    {
-      OemDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_OSTR);
+      OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
       if (OemDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -1189,7 +1060,7 @@ RtlpUnicodeStringToOemString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(OemDest->Buffer, TAG_OSTR);
+      RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
       return Status;
    }
 
@@ -1197,26 +1068,6 @@ RtlpUnicodeStringToOemString(
    return Status;
 }
 
-/*
- * @implemented
- *
- * NOTES
- *  See RtlpUnicodeStringToOemString.
- */
-NTSTATUS
-STDCALL
-RtlUnicodeStringToOemString(
-   IN OUT POEM_STRING OemDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString)
-{
-   return RtlpUnicodeStringToOemString(
-             OemDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
 #define ITU_IMPLEMENTED_TESTS (IS_TEXT_UNICODE_ODD_LENGTH|IS_TEXT_UNICODE_SIGNATURE)
 
 
@@ -1278,35 +1129,31 @@ done:
    return Length;
 }
 
+
 /*
- * private
+ * @implemented
  *
  * NOTES
  *  Same as RtlOemStringToUnicodeString but doesn't write terminating null
  *  A partial copy is NOT performed if the dest buffer is too small!
  */
 NTSTATUS
-FASTCALL
-RtlpOemStringToCountedUnicodeString(
+STDCALL
+RtlOemStringToCountedUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
-   IN POEM_STRING OemSource,
-   IN BOOLEAN AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN PCOEM_STRING OemSource,
+   IN BOOLEAN AllocateDestinationString)
 {
    NTSTATUS Status;
-   ULONG Length; //excluding nullterm
-
-   if (NlsMbCodePageTag == TRUE)
-      Length = RtlOemStringToUnicodeSize(OemSource) - sizeof(WCHAR);
-   else
-      Length = OemSource->Length * sizeof(WCHAR);
+   ULONG Length; /* excluding nullterm */
 
+   Length = RtlOemStringToCountedUnicodeSize(OemSource);
    if (Length > 65535)
       return STATUS_INVALID_PARAMETER_2;
 
    if (AllocateDestinationString == TRUE)
    {
-      UniDest->Buffer = ExAllocatePoolWithTag (PoolType, Length, TAG_USTR);
+      UniDest->Buffer = RtlpAllocateStringMemory (Length, TAG_USTR);
       if (UniDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -1327,33 +1174,13 @@ RtlpOemStringToCountedUnicodeString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(UniDest->Buffer, TAG_USTR);
+      RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
       return Status;
    }
 
    return Status;
 }
 
-/*
- * @implemented
- *
- * NOTES
- *  See RtlpOemStringToCountedUnicodeString
- */
-NTSTATUS
-STDCALL
-RtlOemStringToCountedUnicodeString(
-   IN OUT PUNICODE_STRING UniDest,
-   IN POEM_STRING OemSource,
-   IN BOOLEAN AllocateDestinationString)
-{
-   return RtlpOemStringToCountedUnicodeString(
-             UniDest,
-             OemSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
 /*
  * @implemented
  *
@@ -1577,17 +1404,14 @@ STDCALL
 RtlEraseUnicodeString(
    IN PUNICODE_STRING String)
 {
-   if (String->Buffer == NULL)
-      return;
-
-   if (String->MaximumLength == 0)
-      return;
-
-   memset (String->Buffer,
-           0,
-           String->MaximumLength);
+   if (String->Buffer != NULL &&
+       String->MaximumLength != 0)
+   {
+      RtlZeroMemory (String->Buffer,
+                     String->MaximumLength);
 
-   String->Length = 0;
+      String->Length = 0;
+   }
 }
 
 /*
@@ -1643,28 +1467,23 @@ RtlHashUnicodeString(
 }
 
 /*
- * private
+ * @implemented
  *
  * NOTES
  *  Same as RtlUnicodeStringToOemString but doesn't write terminating null
  *  Does a partial copy if the dest buffer is too small
  */
 NTSTATUS
-FASTCALL
-RtlpUnicodeStringToCountedOemString(
+STDCALL
+RtlUnicodeStringToCountedOemString(
    IN OUT POEM_STRING OemDest,
    IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN BOOLEAN AllocateDestinationString)
 {
    NTSTATUS Status;
    ULONG Length; //excluding nullterm
 
-   if (NlsMbOemCodePageTag == TRUE)
-      Length = RtlUnicodeStringToAnsiSize(UniSource) - sizeof(CHAR);
-   else
-      Length = (UniSource->Length / sizeof(WCHAR));
-
+   Length = RtlUnicodeStringToCountedOemSize(UniSource);
    if (Length > 0x0000FFFF)
       return STATUS_INVALID_PARAMETER_2;
 
@@ -1672,7 +1491,7 @@ RtlpUnicodeStringToCountedOemString(
 
    if (AllocateDestinationString)
    {
-      OemDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_OSTR);
+      OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
       if (OemDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -1695,32 +1514,12 @@ RtlpUnicodeStringToCountedOemString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(OemDest->Buffer, TAG_OSTR);
+      RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
    }
 
    return Status;
 }
 
-/*
- * @implemented
- *
- * NOTES
- *  See RtlpUnicodeStringToCountedOemString.
- */
-NTSTATUS
-STDCALL
-RtlUnicodeStringToCountedOemString(
-   IN OUT POEM_STRING OemDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString)
-{
-   return RtlpUnicodeStringToCountedOemString(
-             OemDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
 /*
  * @implemented
  */
@@ -1759,7 +1558,7 @@ RtlLargeIntegerToChar(
       tp++;
    }
 
-   if (tp - temp >= Length)
+   if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
       return STATUS_BUFFER_TOO_SMALL;
 
    sp = String;
@@ -1771,19 +1570,18 @@ RtlLargeIntegerToChar(
 }
 
 /*
- * private
+ * @implemented
  *
  * NOTES
  *  dest is never '\0' terminated because it may be equal to src, and src
  *  might not be '\0' terminated. dest->Length is only set upon success.
  */
 NTSTATUS
-FASTCALL
-RtlpUpcaseUnicodeString(
+STDCALL
+RtlUpcaseUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
    IN PCUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN BOOLEAN  AllocateDestinationString)
 {
    ULONG i;
    PWCHAR Src, Dest;
@@ -1791,7 +1589,7 @@ RtlpUpcaseUnicodeString(
    if (AllocateDestinationString == TRUE)
    {
       UniDest->MaximumLength = UniSource->Length;
-      UniDest->Buffer = ExAllocatePoolWithTag(PoolType, UniDest->MaximumLength, TAG_USTR);
+      UniDest->Buffer = RtlpAllocateStringMemory(UniDest->MaximumLength, TAG_USTR);
       if (UniDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
    }
@@ -1818,46 +1616,20 @@ RtlpUpcaseUnicodeString(
  * @implemented
  *
  * NOTES
- *  See RtlpUpcaseUnicodeString
- */
-NTSTATUS
-STDCALL
-RtlUpcaseUnicodeString(
-   IN OUT PUNICODE_STRING UniDest,
-   IN PCUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString)
-{
-
-   return RtlpUpcaseUnicodeString(
-             UniDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
-/*
- * private
- *
- * NOTES
  *  This function always writes a terminating '\0'.
  *  It performs a partial copy if ansi is too small.
  */
 NTSTATUS
-FASTCALL
-RtlpUpcaseUnicodeStringToAnsiString(
+STDCALL
+RtlUpcaseUnicodeStringToAnsiString(
    IN OUT PANSI_STRING AnsiDest,
    IN PUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN BOOLEAN  AllocateDestinationString)
 {
    NTSTATUS Status;
-   ULONG Length; //including nullterm
-
-   if (NlsMbCodePageTag == TRUE)
-      Length = RtlUnicodeStringToAnsiSize(UniSource);
-   else
-      Length = (UniSource->Length / sizeof(WCHAR)) + sizeof(CHAR);
+   ULONG Length; /* including nullterm */
 
+   Length = RtlUnicodeStringToAnsiSize(UniSource);
    if (Length > 0x0000FFFF)
       return STATUS_INVALID_PARAMETER_2;
 
@@ -1865,7 +1637,7 @@ RtlpUpcaseUnicodeStringToAnsiString(
 
    if (AllocateDestinationString)
    {
-      AnsiDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_ASTR);
+      AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
       if (AnsiDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -1877,11 +1649,11 @@ RtlpUpcaseUnicodeStringToAnsiString(
    }
    else if (Length > AnsiDest->MaximumLength)
    {
-      //make room for nullterm
+      /* make room for nullterm */
       AnsiDest->Length = AnsiDest->MaximumLength - sizeof(CHAR);
    }
 
-   //FIXME: do we need this??????? -Gunnar
+   /* FIXME: do we need this??????? -Gunnar */
    RtlZeroMemory (AnsiDest->Buffer,
                   AnsiDest->Length);
 
@@ -1893,7 +1665,7 @@ RtlpUpcaseUnicodeStringToAnsiString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(AnsiDest->Buffer, TAG_ASTR);
+      RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
       return Status;
    }
 
@@ -1905,45 +1677,20 @@ RtlpUpcaseUnicodeStringToAnsiString(
  * @implemented
  *
  * NOTES
- *  See RtlpUpcaseUnicodeStringToAnsiString
+ *  This function always writes a terminating '\0'.
+ *  It performs a partial copy if ansi is too small.
  */
 NTSTATUS
 STDCALL
-RtlUpcaseUnicodeStringToAnsiString(
-   IN OUT PANSI_STRING AnsiDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString)
-{
-   return RtlpUpcaseUnicodeStringToAnsiString(
-             AnsiDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
-/*
- * private
- *
- * NOTES
- *  Same as RtlUpcaseUnicodeStringToOemString but doesn't write terminating null
- *  It performs a partial copy if oem is too small.
- */
-NTSTATUS
-FASTCALL
-RtlpUpcaseUnicodeStringToCountedOemString(
+RtlUpcaseUnicodeStringToCountedOemString(
    IN OUT POEM_STRING OemDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN PCUNICODE_STRING UniSource,
+   IN BOOLEAN AllocateDestinationString)
 {
    NTSTATUS Status;
-   ULONG Length; //excluding nullterm
-
-   if (NlsMbCodePageTag == TRUE)
-      Length = RtlUnicodeStringToAnsiSize(UniSource) - sizeof(CHAR);
-   else
-      Length = UniSource->Length / sizeof(WCHAR);
+   ULONG Length; /* excluding nullterm */
 
+   Length = RtlUnicodeStringToCountedOemSize(UniSource);
    if (Length > 0x0000FFFF)
       return(STATUS_INVALID_PARAMETER_2);
 
@@ -1951,11 +1698,11 @@ RtlpUpcaseUnicodeStringToCountedOemString(
 
    if (AllocateDestinationString)
    {
-      OemDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_OSTR);
+      OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
       if (OemDest->Buffer == NULL)
          return(STATUS_NO_MEMORY);
 
-      //FIXME: Do we need this?????
+      /* FIXME: Do we need this????? */
       RtlZeroMemory (OemDest->Buffer, Length);
 
       OemDest->MaximumLength = (WORD)Length;
@@ -1977,7 +1724,7 @@ RtlpUpcaseUnicodeStringToCountedOemString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(OemDest->Buffer, TAG_OSTR);
+      RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
       return Status;
    }
 
@@ -1986,48 +1733,22 @@ RtlpUpcaseUnicodeStringToCountedOemString(
 
 /*
  * @implemented
- *
- * NOTES
- *  See RtlpUpcaseUnicodeStringToCountedOemString
- */
-NTSTATUS
-STDCALL
-RtlUpcaseUnicodeStringToCountedOemString(
-   IN OUT POEM_STRING OemDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString)
-{
-   return RtlpUpcaseUnicodeStringToCountedOemString(
-             OemDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
-/*
- * private
- *
  * NOTES
  *  Oem string is allways nullterminated
  *  It performs a partial copy if oem is too small.
  */
 NTSTATUS
-FASTCALL
-RtlpUpcaseUnicodeStringToOemString (
+STDCALL
+RtlUpcaseUnicodeStringToOemString (
    IN OUT POEM_STRING OemDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString,
-   IN POOL_TYPE PoolType
+   IN PCUNICODE_STRING UniSource,
+   IN BOOLEAN  AllocateDestinationString
 )
 {
    NTSTATUS Status;
-   ULONG Length; //including nullterm
-
-   if (NlsMbOemCodePageTag == TRUE)
-      Length = RtlUnicodeStringToAnsiSize(UniSource);
-   else
-      Length = (UniSource->Length / sizeof(WCHAR)) + sizeof(CHAR);
+   ULONG Length; /* including nullterm */
 
+   Length = RtlUnicodeStringToOemSize(UniSource);
    if (Length > 0x0000FFFF)
       return STATUS_INVALID_PARAMETER_2;
 
@@ -2035,11 +1756,11 @@ RtlpUpcaseUnicodeStringToOemString (
 
    if (AllocateDestinationString)
    {
-      OemDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_OSTR);
+      OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
       if (OemDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
-      //FIXME: Do we need this????
+      /* FIXME: Do we need this???? */
       RtlZeroMemory (OemDest->Buffer, Length);
 
       OemDest->MaximumLength = (WORD)Length;
@@ -2050,7 +1771,7 @@ RtlpUpcaseUnicodeStringToOemString (
    }
    else if (Length > OemDest->MaximumLength)
    {
-      //make room for nullterm
+      /* make room for nullterm */
       OemDest->Length = OemDest->MaximumLength - sizeof(CHAR);
    }
 
@@ -2062,7 +1783,7 @@ RtlpUpcaseUnicodeStringToOemString (
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(OemDest->Buffer, TAG_OSTR);
+      RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
       return Status;
    }
 
@@ -2070,26 +1791,6 @@ RtlpUpcaseUnicodeStringToOemString (
    return Status;
 }
 
-/*
- * @implemented
- * NOTES
- *  See RtlpUpcaseUnicodeStringToOemString
- */
-NTSTATUS
-STDCALL
-RtlUpcaseUnicodeStringToOemString (
-   IN OUT POEM_STRING OemDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN  AllocateDestinationString
-)
-{
-   return RtlpUpcaseUnicodeStringToOemString(
-             OemDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
 /*
  * @implemented
  *
@@ -2098,16 +1799,17 @@ RtlUpcaseUnicodeStringToOemString (
  */
 ULONG
 STDCALL
-RtlOemStringToUnicodeSize(IN POEM_STRING OemString)
+RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString)
 {
-   ULONG Size;
+    ULONG Size;
 
-   //this function returns size including nullterm
-   RtlMultiByteToUnicodeSize(&Size,
-                             OemString->Buffer,
-                             OemString->Length);
+    /* Convert the Mb String to Unicode Size */
+    RtlMultiByteToUnicodeSize(&Size,
+                              OemString->Buffer,
+                              OemString->Length);
 
-   return(Size);
+    /* Return the size + null-char */
+    return (Size + sizeof(WCHAR));
 }
 
 
@@ -2161,72 +1863,52 @@ RtlStringFromGUID (IN REFGUID Guid,
  */
 ULONG
 STDCALL
-RtlUnicodeStringToAnsiSize(
-   IN PUNICODE_STRING UnicodeString)
+RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString)
 {
-   ULONG Size;
+    ULONG Size;
 
-   //this function return size without nullterm!
-   RtlUnicodeToMultiByteSize (&Size,
+    /* Convert the Unicode String to Mb Size */
+    RtlUnicodeToMultiByteSize(&Size,
                               UnicodeString->Buffer,
                               UnicodeString->Length);
 
-   return Size + sizeof(CHAR); //NB: incl. nullterm
+    /* Return the size + null-char */
+    return (Size + sizeof(CHAR));
 }
 
 
-
-
 /*
  * @implemented
  */
 LONG
 STDCALL
 RtlCompareUnicodeString(
-   IN PUNICODE_STRING String1,
-   IN PUNICODE_STRING String2,
+   IN PCUNICODE_STRING s1,
+   IN PCUNICODE_STRING s2,
    IN BOOLEAN  CaseInsensitive)
 {
-   ULONG len1, len2;
-   PWCHAR s1, s2;
-   WCHAR  c1, c2;
+   unsigned int len;
+   LONG ret = 0;
+   LPCWSTR p1, p2;
 
-   if (String1 && String2)
-   {
-      len1 = String1->Length / sizeof(WCHAR);
-      len2 = String2->Length / sizeof(WCHAR);
-      s1 = String1->Buffer;
-      s2 = String2->Buffer;
+   len = min(s1->Length, s2->Length) / sizeof(WCHAR);
+   p1 = s1->Buffer;
+   p2 = s2->Buffer;
 
-      if (s1 && s2)
-      {
-         if (CaseInsensitive)
-         {
-            while (1)
-            {
-               c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
-               c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
-               if (!c1 || !c2 || c1 != c2)
-                  return c1 - c2;
-            }
-         }
-         else
-         {
-            while (1)
-            {
-               c1 = len1-- ? *s1++ : 0;
-               c2 = len2-- ? *s2++ : 0;
-               if (!c1 || !c2 || c1 != c2)
-                  return c1 - c2;
-            }
-         }
-      }
+   if (CaseInsensitive)
+   {
+     while (!ret && len--) ret = RtlUpcaseUnicodeChar(*p1++) - RtlUpcaseUnicodeChar(*p2++);
    }
-
-   return 0;
+   else
+   {
+     while (!ret && len--) ret = *p1++ - *p2++;
+   }
+   if (!ret) ret = s1->Length - s2->Length;
+   return ret;
 }
 
 
+
 /*
  * @implemented
  */
@@ -2264,7 +1946,7 @@ VOID
 STDCALL
 RtlCopyUnicodeString(
    IN OUT PUNICODE_STRING DestinationString,
-   IN PUNICODE_STRING SourceString)
+   IN PCUNICODE_STRING SourceString)
 {
    ULONG copylen;
 
@@ -2285,28 +1967,27 @@ RtlCopyUnicodeString(
 }
 
 /*
- * private
+ * @implemented
  *
+ * NOTES
  * Creates a nullterminated UNICODE_STRING
  */
 BOOLEAN
-FASTCALL
-RtlpCreateUnicodeString(
+STDCALL
+RtlCreateUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
-   IN PCWSTR  Source,
-   IN POOL_TYPE PoolType)
+   IN PCWSTR  Source)
 {
    ULONG Length;
 
    Length = (wcslen (Source) + 1) * sizeof(WCHAR);
-   PoolType = PagedPool;
-   UniDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_USTR);
+   UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
    if (UniDest->Buffer == NULL)
       return FALSE;
 
-   memmove (UniDest->Buffer,
-            Source,
-            Length);
+   RtlCopyMemory (UniDest->Buffer,
+                  Source,
+                  Length);
 
    UniDest->MaximumLength = Length;
    UniDest->Length = Length - sizeof (WCHAR);
@@ -2314,23 +1995,6 @@ RtlpCreateUnicodeString(
    return TRUE;
 }
 
-/*
- * @implemented
- *
- * NOTES
- *  See RtlpCreateUnicodeString
- */
-BOOLEAN
-STDCALL
-RtlCreateUnicodeString(
-   IN OUT PUNICODE_STRING UniDest,
-   IN PCWSTR  Source)
-{
-
-   DPRINT("RtlCreateUnicodeString\n");
-   return RtlpCreateUnicodeString(UniDest, Source, PagedPool);
-}
-
 /*
  * @implemented
  */
@@ -2354,27 +2018,25 @@ RtlCreateUnicodeStringFromAsciiz(
 }
 
 /*
- * private
+ * @implemented
  *
  * NOTES
  *  Dest is never '\0' terminated because it may be equal to src, and src
  *  might not be '\0' terminated.
  *  Dest->Length is only set upon success.
  */
-NTSTATUS
-FASTCALL
-RtlpDowncaseUnicodeString(
+NTSTATUS STDCALL
+RtlDowncaseUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN PCUNICODE_STRING UniSource,
+   IN BOOLEAN AllocateDestinationString)
 {
    ULONG i;
    PWCHAR Src, Dest;
 
    if (AllocateDestinationString)
    {
-      UniDest->Buffer = ExAllocatePoolWithTag(PoolType, UniSource->Length, TAG_USTR);
+      UniDest->Buffer = RtlpAllocateStringMemory(UniSource->Length, TAG_USTR);
       if (UniDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -2411,25 +2073,6 @@ RtlpDowncaseUnicodeString(
    return STATUS_SUCCESS;
 }
 
-/*
- * @implemented
- *
- * NOTES
- *  See RtlpDowncaseUnicodeString
- */
-NTSTATUS STDCALL
-RtlDowncaseUnicodeString(
-   IN OUT PUNICODE_STRING UniDest,
-   IN PUNICODE_STRING UniSource,
-   IN BOOLEAN AllocateDestinationString)
-{
-   return RtlpDowncaseUnicodeString(
-             UniDest,
-             UniSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
 /*
  * @implemented
  *
@@ -2459,34 +2102,29 @@ RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
 }
 
 /*
- * private
+ * @implemented
  *
  * NOTES
  *  This function always writes a terminating '\0'.
  *  If the dest buffer is too small a partial copy is NOT performed!
  */
 NTSTATUS
-FASTCALL
-RtlpAnsiStringToUnicodeString(
+STDCALL
+RtlAnsiStringToUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
    IN PANSI_STRING AnsiSource,
-   IN BOOLEAN AllocateDestinationString,
-   IN POOL_TYPE PoolType)
+   IN BOOLEAN AllocateDestinationString)
 {
    NTSTATUS Status;
    ULONG Length; //including nullterm
 
-   if (NlsMbCodePageTag == TRUE)
-      Length = RtlAnsiStringToUnicodeSize(AnsiSource);
-   else
-      Length = (AnsiSource->Length * sizeof(WCHAR)) + sizeof(WCHAR);
-
+   Length = RtlAnsiStringToUnicodeSize(AnsiSource);
    if (Length > 0xffff)
       return STATUS_INVALID_PARAMETER_2;
 
    if (AllocateDestinationString == TRUE)
    {
-      UniDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_USTR);
+      UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
       if (UniDest->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -2512,7 +2150,7 @@ RtlpAnsiStringToUnicodeString(
 
    if (!NT_SUCCESS(Status) && AllocateDestinationString)
    {
-      ExFreePoolWithTag(UniDest->Buffer, TAG_USTR);
+      RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
       return Status;
    }
 
@@ -2520,26 +2158,6 @@ RtlpAnsiStringToUnicodeString(
    return Status;
 }
 
-/*
- * @implemented
- *
- * NOTES
- *  See RtlpAnsiStringToUnicodeString
- */
-NTSTATUS
-STDCALL
-RtlAnsiStringToUnicodeString(
-   IN OUT PUNICODE_STRING UniDest,
-   IN PANSI_STRING AnsiSource,
-   IN BOOLEAN AllocateDestinationString)
-{
-   return RtlpAnsiStringToUnicodeString(
-             UniDest,
-             AnsiSource,
-             AllocateDestinationString,
-             PagedPool);
-}
-
 /*
  * @implemented
  *
@@ -2604,62 +2222,26 @@ RtlUpperString(PSTRING DestinationString,
    DestinationString->Length = SourceString->Length;
 }
 
-
-/*
- * @implemented
- */
-ULONG STDCALL
-RtlxAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
-{
-   return RtlAnsiStringToUnicodeSize(AnsiString);
-}
-
-
-/*
- * @implemented
- */
-ULONG STDCALL
-RtlxOemStringToUnicodeSize(IN POEM_STRING OemString)
-{
-   return RtlOemStringToUnicodeSize((PANSI_STRING)OemString);
-}
-
-
-
-/*
- * @implemented
- */
-ULONG STDCALL
-RtlxUnicodeStringToAnsiSize(IN PUNICODE_STRING UnicodeString)
-{
-   return RtlUnicodeStringToAnsiSize(UnicodeString);
-}
-
-
-/*
- * @implemented
- */
-ULONG STDCALL
-RtlxUnicodeStringToOemSize(IN PUNICODE_STRING UnicodeString)
-{
-   return RtlUnicodeStringToOemSize(UnicodeString);
-}
-
 /*
  * @implemented
+ *
+ * NOTES
+ *  See RtlpDuplicateUnicodeString
  */
-NTSTATUS STDCALL
-RtlpDuplicateUnicodeString(
-   INT AddNull,
-   IN PUNICODE_STRING SourceString,
-   PUNICODE_STRING DestinationString,
-   POOL_TYPE PoolType)
+NTSTATUS
+STDCALL
+RtlDuplicateUnicodeString(
+   IN ULONG Flags,
+   IN PCUNICODE_STRING SourceString,
+   OUT PUNICODE_STRING DestinationString)
 {
    if (SourceString == NULL || DestinationString == NULL)
       return STATUS_INVALID_PARAMETER;
 
 
-   if (SourceString->Length == 0 && AddNull != 3)
+   if ((SourceString->Length == 0) && 
+       (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | 
+                  RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING)))
    {
       DestinationString->Length = 0;
       DestinationString->MaximumLength = 0;
@@ -2667,12 +2249,12 @@ RtlpDuplicateUnicodeString(
    }
    else
    {
-      unsigned int DestMaxLength = SourceString->Length;
+      UINT DestMaxLength = SourceString->Length;
 
-      if (AddNull)
+      if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
          DestMaxLength += sizeof(UNICODE_NULL);
 
-      DestinationString->Buffer = ExAllocatePool(PoolType, DestMaxLength);
+      DestinationString->Buffer = RtlpAllocateStringMemory(DestMaxLength, TAG_USTR);
       if (DestinationString->Buffer == NULL)
          return STATUS_NO_MEMORY;
 
@@ -2680,32 +2262,13 @@ RtlpDuplicateUnicodeString(
       DestinationString->Length = SourceString->Length;
       DestinationString->MaximumLength = DestMaxLength;
 
-      if (AddNull)
+      if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
          DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0;
    }
 
    return STATUS_SUCCESS;
 }
 
-/*
- * @implemented
- *
- * NOTES
- *  See RtlpDuplicateUnicodeString
- */
-NTSTATUS STDCALL
-RtlDuplicateUnicodeString(
-   INT AddNull,
-   IN PUNICODE_STRING SourceString,
-   PUNICODE_STRING DestinationString)
-{
-   return RtlpDuplicateUnicodeString(
-            AddNull,
-            SourceString,
-            DestinationString,
-            PagedPool);
-}
-
 /*
  * @implemented
  */