* 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;
} else {
digit = -1;
} /* if */
- if (digit < 0 || digit >= base) {
+ if (digit < 0 || digit >= (int)base) {
*value = bMinus ? -RunningTotal : RunningTotal;
return STATUS_SUCCESS;
} /* if */
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 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 );
}
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;
+ }
}
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;
+ }
}
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;
+ }
}
/*
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;
}
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;
}
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) {
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 */
}
/*
- * 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 BOOLEAN AllocateDestinationString)
{
NTSTATUS Status = STATUS_SUCCESS;
- ULONG Length; //including nullterm
+ ULONG Length; /* including nullterm */
if (NlsMbCodePageTag == TRUE)
{
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)
{
- ExFreePoolWithTag(AnsiDest->Buffer, TAG_ASTR);
+ RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
return Status;
}
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 BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
- ULONG Length; //including nullterm
+ ULONG Length; /* including nullterm */
if (NlsMbOemCodePageTag == TRUE)
Length = RtlOemStringToUnicodeSize(OemSource);
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)
{
- ExFreePoolWithTag(UniDest->Buffer, TAG_USTR);
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
return Status;
}
* @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 BOOLEAN AllocateDestinationString)
{
NTSTATUS Status = STATUS_SUCCESS;
ULONG Length; //including nullterm
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)
{
- ExFreePoolWithTag(OemDest->Buffer, TAG_OSTR);
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
return Status;
}
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)
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 BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
- ULONG Length; //excluding nullterm
+ ULONG Length; /* excluding nullterm */
if (NlsMbCodePageTag == TRUE)
Length = RtlOemStringToUnicodeSize(OemSource) - sizeof(WCHAR);
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)
{
- 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
*
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;
+ }
}
/*
}
/*
- * 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 (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)
{
- 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
*/
tp++;
}
- if (tp - temp >= Length)
+ if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
return STATUS_BUFFER_TOO_SMALL;
sp = String;
}
/*
- * 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;
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;
}
* @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
+ ULONG Length; /* including nullterm */
if (NlsMbCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize(UniSource);
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)
{
- ExFreePoolWithTag(AnsiDest->Buffer, TAG_ASTR);
+ RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
return Status;
}
* @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 BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
- ULONG Length; //excluding nullterm
+ ULONG Length; /* excluding nullterm */
if (NlsMbCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize(UniSource) - sizeof(CHAR);
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)
{
- ExFreePoolWithTag(OemDest->Buffer, TAG_OSTR);
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
return Status;
}
/*
* @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 BOOLEAN AllocateDestinationString
)
{
NTSTATUS Status;
- ULONG Length; //including nullterm
+ ULONG Length; /* including nullterm */
if (NlsMbOemCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize(UniSource);
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)
{
- ExFreePoolWithTag(OemDest->Buffer, TAG_OSTR);
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
return Status;
}
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
*
}
-
-
/*
* @implemented
*/
LONG
STDCALL
RtlCompareUnicodeString(
- IN PUNICODE_STRING String1,
- IN PUNICODE_STRING String2,
+ IN PUNICODE_STRING s1,
+ IN PUNICODE_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
*/
}
/*
- * 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);
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
*/
}
/*
- * 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 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;
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
*
}
/*
- * 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 (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)
{
- ExFreePoolWithTag(UniDest->Buffer, TAG_USTR);
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
return Status;
}
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
*
ULONG STDCALL
RtlxOemStringToUnicodeSize(IN POEM_STRING OemString)
{
- return RtlOemStringToUnicodeSize((PANSI_STRING)OemString);
+ return RtlOemStringToUnicodeSize(OemString);
}
/*
* @implemented
+ *
+ * NOTES
+ * See RtlpDuplicateUnicodeString
*/
NTSTATUS STDCALL
-RtlpDuplicateUnicodeString(
+RtlDuplicateUnicodeString(
INT AddNull,
IN PUNICODE_STRING SourceString,
- PUNICODE_STRING DestinationString,
- POOL_TYPE PoolType)
+ PUNICODE_STRING DestinationString)
{
if (SourceString == NULL || DestinationString == NULL)
return STATUS_INVALID_PARAMETER;
}
else
{
- unsigned int DestMaxLength = SourceString->Length;
+ UINT DestMaxLength = SourceString->Length;
if (AddNull)
DestMaxLength += sizeof(UNICODE_NULL);
- DestinationString->Buffer = ExAllocatePool(PoolType, DestMaxLength);
+ DestinationString->Buffer = RtlpAllocateStringMemory(DestMaxLength, TAG_USTR);
if (DestinationString->Buffer == NULL)
return STATUS_NO_MEMORY;
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
*/