* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
-
#define __NTDRIVER__
-#include <ddk/ntddk.h>
-
-#include <ntdll/rtl.h>
-
-#include <ntos/minmax.h>
-#define __NO_CTYPE_INLINES
-#include <ctype.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;
*/
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));
}
STDCALL
RtlAppendUnicodeStringToString(
IN OUT PUNICODE_STRING Destination,
- IN PUNICODE_STRING Source)
+ IN PCUNICODE_STRING Source)
{
if ((Source->Length + Destination->Length) > Destination->MaximumLength)
}
-/*
+/**************************************************************************
+ * RtlCharToInteger (NTDLL.@)
* @implemented
+ * Converts a character string into its integer equivalent.
+ *
+ * RETURNS
+ * Success: STATUS_SUCCESS. value contains the converted number
+ * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
+ * STATUS_ACCESS_VIOLATION, if value is NULL.
+ *
+ * NOTES
+ * For base 0 it uses 10 as base and the string should be in the format
+ * "{whitespace} [+|-] [0[x|o|b]] {digits}".
+ * For other bases the string should be in the format
+ * "{whitespace} [+|-] {digits}".
+ * No check is made for value overflow, only the lower 32 bits are assigned.
+ * If str is NULL it crashes, as the native function does.
+ *
+ * DIFFERENCES
+ * This function does not read garbage behind '\0' as the native version does.
*/
NTSTATUS
STDCALL
RtlCharToInteger(
- IN PCSZ String,
- IN ULONG Base,
- IN OUT PULONG Value)
-{
- ULONG Val;
-
- *Value = 0;
-
- if (Base == 0)
- {
- Base = 10;
- if (*String == '0')
- {
- Base = 8;
- String++;
- if ((*String == 'x') && isxdigit (String[1]))
- {
- String++;
- Base = 16;
- }
- }
- }
-
- if (!isxdigit (*String))
- return STATUS_INVALID_PARAMETER;
-
- while (isxdigit (*String) &&
- (Val = isdigit (*String) ? * String - '0' : (islower (*String)
- ? toupper (*String) : *String) - 'A' + 10) < Base)
- {
- *Value = *Value * Base + Val;
- String++;
- }
-
- return STATUS_SUCCESS;
+ PCSZ str, /* [I] '\0' terminated single-byte string containing a number */
+ ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
+ PULONG value) /* [O] Destination for the converted value */
+{
+ CHAR chCurrent;
+ int digit;
+ ULONG RunningTotal = 0;
+ char bMinus = 0;
+
+ while (*str != '\0' && *str <= ' ') {
+ str++;
+ } /* while */
+
+ if (*str == '+') {
+ str++;
+ } else if (*str == '-') {
+ bMinus = 1;
+ str++;
+ } /* if */
+
+ if (base == 0) {
+ base = 10;
+ if (str[0] == '0') {
+ if (str[1] == 'b') {
+ str += 2;
+ base = 2;
+ } else if (str[1] == 'o') {
+ str += 2;
+ base = 8;
+ } else if (str[1] == 'x') {
+ str += 2;
+ base = 16;
+ } /* if */
+ } /* if */
+ } else if (base != 2 && base != 8 && base != 10 && base != 16) {
+ return STATUS_INVALID_PARAMETER;
+ } /* if */
+
+ if (value == NULL) {
+ return STATUS_ACCESS_VIOLATION;
+ } /* if */
+
+ while (*str != '\0') {
+ chCurrent = *str;
+ if (chCurrent >= '0' && chCurrent <= '9') {
+ digit = chCurrent - '0';
+ } else if (chCurrent >= 'A' && chCurrent <= 'Z') {
+ digit = chCurrent - 'A' + 10;
+ } else if (chCurrent >= 'a' && chCurrent <= 'z') {
+ digit = chCurrent - 'a' + 10;
+ } else {
+ digit = -1;
+ } /* if */
+ if (digit < 0 || digit >= (int)base) {
+ *value = bMinus ? -RunningTotal : RunningTotal;
+ return STATUS_SUCCESS;
+ } /* if */
+
+ RunningTotal = RunningTotal * base + digit;
+ str++;
+ } /* while */
+
+ *value = bMinus ? -RunningTotal : RunningTotal;
+ return STATUS_SUCCESS;
}
-
-
/*
* @implemented
*/
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;
}
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 );
}
BOOLEAN
STDCALL
RtlEqualUnicodeString(
- IN PUNICODE_STRING String1,
- IN PUNICODE_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 );
}
STDCALL
RtlFreeAnsiString(IN PANSI_STRING AnsiString)
{
- if (AnsiString->Buffer == NULL)
- return;
-
- ExFreePool(AnsiString->Buffer);
+ 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;
+ }
}
STDCALL
RtlFreeOemString(IN POEM_STRING OemString)
{
- if (OemString->Buffer == NULL)
- return;
-
- ExFreePool(OemString->Buffer);
+ 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;
+ }
}
STDCALL
RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
{
- if (UnicodeString->Buffer == NULL)
- return;
-
- ExFreePool(UnicodeString->Buffer);
+ 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;
+ }
}
/*
{
ULONG DestSize;
- DPRINT("RtlInitUnicodeString(DestinationString %x, SourceString %x)\n",
+ DPRINT("RtlInitUnicodeString(DestinationString 0x%p, SourceString 0x%p)\n",
DestinationString,
SourceString);
tp++;
}
- if (tp - temp >= Length)
+ if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
{
return STATUS_BUFFER_TOO_SMALL;
}
tp++;
}
- if (tp - temp >= Length)
+ if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
{
return STATUS_BUFFER_TOO_SMALL;
}
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;
}
ANSI_STRING AnsiString;
CHAR Buffer[33];
NTSTATUS Status;
-
+
LargeInt.QuadPart = Value;
Status = RtlLargeIntegerToChar (&LargeInt,
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;
}
BOOLEAN
STDCALL
RtlPrefixUnicodeString(
- PUNICODE_STRING String1,
- PUNICODE_STRING String2,
+ PCUNICODE_STRING String1,
+ PCUNICODE_STRING String2,
BOOLEAN CaseInsensitive)
{
PWCHAR pc1;
return FALSE;
}
-
-
-/*
+/**************************************************************************
+ * RtlUnicodeStringToInteger (NTDLL.@)
* @implemented
+ * Converts an unicode string into its integer equivalent.
+ *
+ * RETURNS
+ * Success: STATUS_SUCCESS. value contains the converted number
+ * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
+ * STATUS_ACCESS_VIOLATION, if value is NULL.
*
- * Note that regardless of success or failure status, we should leave the
- * partial value in Value. An error is never returned based on the chars
- * in the string.
+ * NOTES
+ * For base 0 it uses 10 as base and the string should be in the format
+ * "{whitespace} [+|-] [0[x|o|b]] {digits}".
+ * For other bases the string should be in the format
+ * "{whitespace} [+|-] {digits}".
+ * No check is made for value overflow, only the lower 32 bits are assigned.
+ * If str is NULL it crashes, as the native function does.
*
- * This function does check the base. Only 2, 8, 10, 16 are permitted,
- * else STATUS_INVALID_PARAMETER is returned.
+ * Note that regardless of success or failure status, we should leave the
+ * partial value in Value. An error is never returned based on the chars
+ * in the string.
+ *
+ * DIFFERENCES
+ * This function does not read garbage on string length 0 as the native
+ * version does.
*/
NTSTATUS
STDCALL
RtlUnicodeStringToInteger(
- IN PUNICODE_STRING String,
- IN ULONG Base,
- OUT PULONG Value)
-{
- PWCHAR Str;
- ULONG lenmin = 0;
- ULONG i;
- ULONG Val;
- BOOLEAN addneg = FALSE;
- NTSTATUS Status = STATUS_SUCCESS;
-
- *Value = 0;
- Str = String->Buffer;
-
- if( Base && Base != 2 && Base != 8 && Base != 10 && Base != 16 )
- return STATUS_INVALID_PARAMETER;
-
- for (i = 0; i < String->Length / sizeof(WCHAR); i++)
- {
- if (*Str == L'b')
- {
- Base = 2;
- lenmin++;
- }
- else if (*Str == L'o')
- {
- Base = 8;
- lenmin++;
- }
- else if (*Str == L'd')
- {
- Base = 10;
- lenmin++;
- }
- else if (*Str == L'x')
- {
- Base = 16;
- lenmin++;
- }
- else if (*Str == L'+')
- {
- lenmin++;
- }
- else if (*Str == L'-')
- {
- addneg = TRUE;
- lenmin++;
- }
- else if ((*Str > L'1') && (Base == 2))
- {
- break;
- }
- else if (((*Str > L'7') || (*Str < L'0')) && (Base == 8))
- {
- break;
- }
- else if (((*Str > L'9') || (*Str < L'0')) && (Base == 10))
- {
- break;
- }
- else if ( ((*Str > L'9') || (*Str < L'0')) &&
- ((towupper (*Str) > L'F') || (towupper (*Str) < L'A')) &&
- (Base == 16))
- {
- break;
- }
- Str++;
- }
-
- Str = String->Buffer + lenmin;
-
- if (Base == 0)
- Base = 10;
-
- while (iswxdigit (*Str) &&
- (Val =
- iswdigit (*Str) ?
- *Str - L'0' :
- (towupper (*Str) - L'A' + 10)) < Base)
- {
- *Value = *Value * Base + Val;
- Str++;
- }
-
- if (addneg == TRUE)
- *Value *= -1;
-
- return Status;
+ 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 */
+{
+ LPWSTR lpwstr = str->Buffer;
+ USHORT CharsRemaining = str->Length / sizeof(WCHAR);
+ WCHAR wchCurrent;
+ int digit;
+ ULONG newbase = 0;
+ ULONG RunningTotal = 0;
+ char bMinus = 0;
+
+ while (CharsRemaining >= 1 && *lpwstr <= L' ') {
+ lpwstr++;
+ CharsRemaining--;
+ } /* while */
+
+ if (CharsRemaining >= 1) {
+ if (*lpwstr == L'+') {
+ lpwstr++;
+ CharsRemaining--;
+ } else if (*lpwstr == L'-') {
+ bMinus = 1;
+ lpwstr++;
+ CharsRemaining--;
+ } /* if */
+ } /* 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 */
+ }
+ 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) {
+ return STATUS_ACCESS_VIOLATION;
+ } /* if */
+
+ while (CharsRemaining >= 1) {
+ wchCurrent = *lpwstr;
+ 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 >= (int)base) {
+ *value = bMinus ? -RunningTotal : RunningTotal;
+ return STATUS_SUCCESS;
+ } /* if */
+
+ RunningTotal = RunningTotal * base + digit;
+ lpwstr++;
+ CharsRemaining--;
+ } /* while */
+
+ *value = bMinus ? -RunningTotal : RunningTotal;
+ return STATUS_SUCCESS;
}
-
/*
* @implemented
*
*/
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));
}
-
/*
* @implemented
*
-
- * NOTES
- * See RtlpUnicodeStringToAnsiString
- */
-NTSTATUS
-STDCALL
-RtlUnicodeStringToAnsiString(
- IN OUT PANSI_STRING AnsiDest,
- IN PUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString)
-{
- return RtlpUnicodeStringToAnsiString(
- AnsiDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-/*
- * private
- *
* 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;
}
else if (Length > AnsiDest->MaximumLength)
{
- //make room for nullterm
+ /* make room for nullterm */
AnsiDest->Length = AnsiDest->MaximumLength - sizeof(CHAR);
}
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool (AnsiDest->Buffer);
+ RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
return Status;
}
* @implemented
*
* NOTES
- * See RtlpOemStringToUnicodeString
+ * This function always writes a terminating '\0'.
+ * Does NOT perform a partial copy if unicode is too small!
*/
NTSTATUS
STDCALL
RtlOemStringToUnicodeString(
IN OUT PUNICODE_STRING UniDest,
- IN POEM_STRING OemSource,
+ IN PCOEM_STRING OemSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpOemStringToUnicodeString(
- UniDest,
- OemSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-/*
- * private
- *
- * NOTES
- * This function always writes a terminating '\0'.
- * Does NOT perform a partial copy if unicode is too small!
- */
-NTSTATUS
-FASTCALL
-RtlpOemStringToUnicodeString(
- IN OUT PUNICODE_STRING UniDest,
- IN POEM_STRING OemSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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;
if (AllocateDestinationString)
{
- UniDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_USTR);
+ UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
if (UniDest->Buffer == NULL)
return STATUS_NO_MEMORY;
return STATUS_BUFFER_TOO_SMALL;
}
- //FIXME: Do we need this????? -Gunnar
+ /* FIXME: Do we need this????? -Gunnar */
RtlZeroMemory (UniDest->Buffer,
UniDest->Length);
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool (UniDest->Buffer);
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
return Status;
}
* @implemented
*
* NOTES
- * See RtlpUnicodeStringToOemString.
+ * This function always '\0' terminates the string returned.
*/
NTSTATUS
STDCALL
RtlUnicodeStringToOemString(
IN OUT POEM_STRING OemDest,
- IN PUNICODE_STRING UniSource,
+ IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpUnicodeStringToOemString(
- OemDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-
-/*
- * private
- *
- * NOTES
- * This function always '\0' terminates the string returned.
- */
-NTSTATUS
-FASTCALL
-RtlpUnicodeStringToOemString(
- IN OUT POEM_STRING OemDest,
- IN PUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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;
if (AllocateDestinationString)
{
- OemDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_OSTR);
+ OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
if (OemDest->Buffer == NULL)
return STATUS_NO_MEMORY;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool(OemDest->Buffer);
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
return Status;
}
return Status;
}
-
-
#define ITU_IMPLEMENTED_TESTS (IS_TEXT_UNICODE_ODD_LENGTH|IS_TEXT_UNICODE_SIGNATURE)
* @implemented
*
* NOTES
- * See RtlpOemStringToCountedUnicodeString
+ * Same as RtlOemStringToUnicodeString but doesn't write terminating null
+ * A partial copy is NOT performed if the dest buffer is too small!
*/
NTSTATUS
STDCALL
RtlOemStringToCountedUnicodeString(
IN OUT PUNICODE_STRING UniDest,
- IN POEM_STRING OemSource,
+ IN PCOEM_STRING OemSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpOemStringToCountedUnicodeString(
- UniDest,
- OemSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-/*
- * private
- *
- * 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(
- IN OUT PUNICODE_STRING UniDest,
- IN POEM_STRING OemSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool (UniDest->Buffer);
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
return Status;
}
return Status;
}
-
/*
* @implemented
*
OEM_STRING OemString1;
OEM_STRING OemString2;
BOOLEAN Result;
-
+
RtlUpcaseUnicodeStringToOemString (&OemString1,
DomainName1,
TRUE);
RtlUpcaseUnicodeStringToOemString (&OemString2,
DomainName2,
TRUE);
-
+
Result = RtlEqualString (&OemString1,
&OemString2,
FALSE);
-
+
RtlFreeOemString (&OemString1);
RtlFreeOemString (&OemString2);
-
+
return Result;
-
+
}
*/
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;
+ }
}
/*
-* @unimplemented
+* @implemented
*/
NTSTATUS
STDCALL
RtlHashUnicodeString(
- IN const UNICODE_STRING *String,
- IN BOOLEAN CaseInSensitive,
- IN ULONG HashAlgorithm,
- OUT PULONG HashValue
- )
-{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
+ IN CONST UNICODE_STRING *String,
+ IN BOOLEAN CaseInSensitive,
+ IN ULONG HashAlgorithm,
+ OUT PULONG HashValue)
+{
+ if (String != NULL && HashValue != NULL)
+ {
+ switch (HashAlgorithm)
+ {
+ case HASH_STRING_ALGORITHM_DEFAULT:
+ case HASH_STRING_ALGORITHM_X65599:
+ {
+ WCHAR *c, *end;
+
+ *HashValue = 0;
+ end = String->Buffer + (String->Length / sizeof(WCHAR));
+
+ if (CaseInSensitive)
+ {
+ for (c = String->Buffer;
+ c != end;
+ c++)
+ {
+ /* only uppercase characters if they are 'a' ... 'z'! */
+ *HashValue = ((65599 * (*HashValue)) +
+ (ULONG)(((*c) >= L'a' && (*c) <= L'z') ?
+ (*c) - L'a' + L'A' : (*c)));
+ }
+ }
+ else
+ {
+ for (c = String->Buffer;
+ c != end;
+ c++)
+ {
+ *HashValue = ((65599 * (*HashValue)) + (ULONG)(*c));
+ }
+ }
+ return STATUS_SUCCESS;
+ }
+ }
+ }
+
+ return STATUS_INVALID_PARAMETER;
}
/*
* @implemented
*
* NOTES
- * See RtlpUnicodeStringToCountedOemString.
+ * Same as RtlUnicodeStringToOemString but doesn't write terminating null
+ * Does a partial copy if the dest buffer is too small
*/
NTSTATUS
STDCALL
IN OUT POEM_STRING OemDest,
IN PUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpUnicodeStringToCountedOemString(
- OemDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-/*
- * private
- *
- * NOTES
- * Same as RtlUnicodeStringToOemString but doesn't write terminating null
- * Does a partial copy if the dest buffer is too small
- */
-NTSTATUS
-FASTCALL
-RtlpUnicodeStringToCountedOemString(
- IN OUT POEM_STRING OemDest,
- IN PUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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;
if (AllocateDestinationString)
{
- OemDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_OSTR);
+ OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
if (OemDest->Buffer == NULL)
return STATUS_NO_MEMORY;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool(OemDest->Buffer);
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
}
return Status;
}
-
/*
* @implemented
*/
tp++;
}
- if (tp - temp >= Length)
+ if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
return STATUS_BUFFER_TOO_SMALL;
sp = String;
return STATUS_SUCCESS;
}
-
-
/*
* @implemented
*
* NOTES
- * See RtlpUpcaseUnicodeString
+ * 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
STDCALL
IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
-
- return RtlpUpcaseUnicodeString(
- UniDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-/*
- * private
- *
- * 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(
- IN OUT PUNICODE_STRING UniDest,
- IN PCUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
-{
ULONG i;
PWCHAR Src, Dest;
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;
}
return STATUS_SUCCESS;
}
-
-
/*
* @implemented
*
* NOTES
- * See RtlpUpcaseUnicodeStringToAnsiString
+ * This function always writes a terminating '\0'.
+ * It performs a partial copy if ansi is too small.
*/
NTSTATUS
STDCALL
IN OUT PANSI_STRING AnsiDest,
IN PUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpUpcaseUnicodeStringToAnsiString(
- AnsiDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-/*
- * private
- *
- * NOTES
- * This function always writes a terminating '\0'.
- * It performs a partial copy if ansi is too small.
- */
-NTSTATUS
-FASTCALL
-RtlpUpcaseUnicodeStringToAnsiString(
- IN OUT PANSI_STRING AnsiDest,
- IN PUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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;
if (AllocateDestinationString)
{
- AnsiDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG_ASTR);
+ AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
if (AnsiDest->Buffer == NULL)
return STATUS_NO_MEMORY;
}
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);
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool(AnsiDest->Buffer);
+ RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
return Status;
}
return Status;
}
-
-
/*
* @implemented
*
* NOTES
- * See RtlpUpcaseUnicodeStringToCountedOemString
+ * This function always writes a terminating '\0'.
+ * It performs a partial copy if ansi is too small.
*/
NTSTATUS
STDCALL
RtlUpcaseUnicodeStringToCountedOemString(
IN OUT POEM_STRING OemDest,
- IN PUNICODE_STRING UniSource,
+ IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpUpcaseUnicodeStringToCountedOemString(
- OemDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-
-/*
- * private
- *
- * NOTES
- * Same as RtlUpcaseUnicodeStringToOemString but doesn't write terminating null
- * It performs a partial copy if oem is too small.
- */
-NTSTATUS
-FASTCALL
-RtlpUpcaseUnicodeStringToCountedOemString(
- IN OUT POEM_STRING OemDest,
- IN PUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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);
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;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool(OemDest->Buffer);
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
return Status;
}
return Status;
}
-
/*
* @implemented
* NOTES
- * See RtlpUpcaseUnicodeStringToOemString
+ * Oem string is allways nullterminated
+ * It performs a partial copy if oem is too small.
*/
NTSTATUS
STDCALL
RtlUpcaseUnicodeStringToOemString (
IN OUT POEM_STRING OemDest,
- IN PUNICODE_STRING UniSource,
+ IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString
)
-{
- return RtlpUpcaseUnicodeStringToOemString(
- OemDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-/*
- * private
- *
- * NOTES
- * Oem string is allways nullterminated
- * It performs a partial copy if oem is too small.
- */
-NTSTATUS
-FASTCALL
-RtlpUpcaseUnicodeStringToOemString (
- IN OUT POEM_STRING OemDest,
- IN PUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType
-)
{
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;
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;
}
else if (Length > OemDest->MaximumLength)
{
- //make room for nullterm
+ /* make room for nullterm */
OemDest->Length = OemDest->MaximumLength - sizeof(CHAR);
}
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool(OemDest->Buffer);
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
return Status;
}
return Status;
}
-
/*
* @implemented
*
*/
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));
}
*/
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
*/
STDCALL
RtlCopyUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
- IN PUNICODE_STRING SourceString)
+ IN PCUNICODE_STRING SourceString)
{
ULONG copylen;
DestinationString->Length = copylen;
}
-
/*
* @implemented
*
* NOTES
- * See RtlpCreateUnicodeString
+ * Creates a nullterminated UNICODE_STRING
*/
BOOLEAN
STDCALL
IN OUT PUNICODE_STRING UniDest,
IN PCWSTR Source)
{
-
- DPRINT("RtlCreateUnicodeString\n");
- return RtlpCreateUnicodeString(UniDest, Source, NonPagedPool);
-}
-
-
-/*
- * private
- *
- * Creates a nullterminated UNICODE_STRING
- */
-BOOLEAN
-FASTCALL
-RtlpCreateUnicodeString(
- IN OUT PUNICODE_STRING UniDest,
- IN PCWSTR Source,
- IN POOL_TYPE PoolType)
-{
ULONG Length;
Length = (wcslen (Source) + 1) * sizeof(WCHAR);
-
- 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);
return TRUE;
}
-
-
/*
* @implemented
*/
return NT_SUCCESS(Status);
}
-
-
/*
* @implemented
*
* NOTES
- * See RtlpDowncaseUnicodeString
+ * 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 STDCALL
RtlDowncaseUnicodeString(
IN OUT PUNICODE_STRING UniDest,
- IN PUNICODE_STRING UniSource,
+ IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpDowncaseUnicodeString(
- UniDest,
- UniSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-/*
- * private
- *
- * 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(
- IN OUT PUNICODE_STRING UniDest,
- IN PUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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;
return STATUS_SUCCESS;
}
-
-
/*
* @implemented
*
return(STATUS_SUCCESS);
}
-
/*
* @implemented
*
* NOTES
- * See RtlpAnsiStringToUnicodeString
+ * This function always writes a terminating '\0'.
+ * If the dest buffer is too small a partial copy is NOT performed!
*/
NTSTATUS
STDCALL
IN OUT PUNICODE_STRING UniDest,
IN PANSI_STRING AnsiSource,
IN BOOLEAN AllocateDestinationString)
-{
- return RtlpAnsiStringToUnicodeString(
- UniDest,
- AnsiSource,
- AllocateDestinationString,
- NonPagedPool);
-}
-
-
-
-/*
- * private
- *
- * NOTES
- * This function always writes a terminating '\0'.
- * If the dest buffer is too small a partial copy is NOT performed!
- */
-NTSTATUS
-FASTCALL
-RtlpAnsiStringToUnicodeString(
- IN OUT PUNICODE_STRING UniDest,
- IN PANSI_STRING AnsiSource,
- IN BOOLEAN AllocateDestinationString,
- IN POOL_TYPE PoolType)
{
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;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
- ExFreePool(UniDest->Buffer);
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
return Status;
}
return Status;
}
-
-
/*
* @implemented
*
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
+NTSTATUS
+STDCALL
RtlDuplicateUnicodeString(
- INT AddNull,
- IN PUNICODE_STRING SourceString,
- PUNICODE_STRING DestinationString)
-{
- return RtlpDuplicateUnicodeString(
- AddNull,
- SourceString,
- DestinationString,
- NonPagedPool);
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-RtlpDuplicateUnicodeString(
- INT AddNull,
- IN PUNICODE_STRING SourceString,
- PUNICODE_STRING DestinationString,
- POOL_TYPE PoolType)
+ 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;
}
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;
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
*/
{
/* currently no flags are supported! */
ASSERT(Flags == 0);
-
+
if ((Flags == 0) &&
((UnicodeString == NULL) ||
((UnicodeString->Length != 0) &&