* PROJECT: ReactOS system libraries
* PURPOSE: Unicode Conversion Routines
* FILE: lib/rtl/unicode.c
- * PROGRAMMER:
+ * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
+ * Emanuele Aliberti
+ * Gunnar Dalsnes
*/
/* INCLUDES *****************************************************************/
extern BOOLEAN NlsMbCodePageTag;
extern BOOLEAN NlsMbOemCodePageTag;
+extern PUSHORT NlsLeadByteInfo;
/* FUNCTIONS *****************************************************************/
-
/*
* @implemented
*/
-WCHAR STDCALL
-RtlAnsiCharToUnicodeChar (IN CHAR AnsiChar)
+WCHAR
+NTAPI
+RtlAnsiCharToUnicodeChar(IN PUCHAR *AnsiChar)
{
- ULONG Size;
- WCHAR UnicodeChar;
+ ULONG Size;
+ NTSTATUS Status;
+ WCHAR UnicodeChar = L' ';
- Size = 1;
-#if 0
+ Size = (NlsLeadByteInfo[**AnsiChar] == 0) ? 1 : 2;
- Size = (NlsLeadByteInfo[AnsiChar] == 0) ? 1 : 2;
-#endif
+ Status = RtlMultiByteToUnicodeN(&UnicodeChar,
+ sizeof(WCHAR),
+ NULL,
+ (PCHAR)*AnsiChar,
+ Size);
- RtlMultiByteToUnicodeN (&UnicodeChar,
- sizeof(WCHAR),
- NULL,
- &AnsiChar,
- Size);
+ if (!NT_SUCCESS(Status))
+ {
+ UnicodeChar = L' ';
+ }
- return UnicodeChar;
+ *AnsiChar += Size;
+ return UnicodeChar;
}
+/*
+ * @implemented
+ *
+ * NOTES
+ * This function always writes a terminating '\0'.
+ * If the dest buffer is too small a partial copy is NOT performed!
+ */
+NTSTATUS
+NTAPI
+RtlAnsiStringToUnicodeString(
+ IN OUT PUNICODE_STRING UniDest,
+ IN PANSI_STRING AnsiSource,
+ IN BOOLEAN AllocateDestinationString)
+{
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
+
+ PAGED_CODE_RTL();
+
+ Length = RtlAnsiStringToUnicodeSize(AnsiSource);
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
+ UniDest->Length = (USHORT)Length - sizeof(WCHAR);
+
+ if (AllocateDestinationString)
+ {
+ UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
+ UniDest->MaximumLength = Length;
+ if (!UniDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (UniDest->Length >= UniDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
+
+ Status = RtlMultiByteToUnicodeN(UniDest->Buffer,
+ UniDest->Length,
+ &Index,
+ AnsiSource->Buffer,
+ AnsiSource->Length);
+
+ if (!NT_SUCCESS(Status))
+ {
+ if (AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
+ UniDest->Buffer = NULL;
+ }
+ return Status;
+ }
+
+ UniDest->Buffer[Index / sizeof(WCHAR)] = UNICODE_NULL;
+ return Status;
+}
/*
* @implemented
* The calculated size in bytes including nullterm.
*/
ULONG
-STDCALL
+NTAPI
RtlxAnsiStringToUnicodeSize(IN PCANSI_STRING AnsiString)
{
ULONG Size;
return(Size + sizeof(WCHAR));
}
-
-
/*
* @implemented
*
* Dest is never nullterminated.
*/
NTSTATUS
-STDCALL
-RtlAppendStringToString(IN OUT PSTRING Destination,
+NTAPI
+RtlAppendStringToString(IN PSTRING Destination,
IN PSTRING Source)
{
- PCHAR Ptr;
-
- if (Source->Length == 0)
- return(STATUS_SUCCESS);
+ USHORT SourceLength = Source->Length;
- if (Destination->Length + Source->Length >= Destination->MaximumLength)
- return(STATUS_BUFFER_TOO_SMALL);
+ if (SourceLength)
+ {
+ if (Destination->Length + SourceLength > Destination->MaximumLength)
+ {
+ return STATUS_BUFFER_TOO_SMALL;
+ }
- Ptr = Destination->Buffer + Destination->Length;
- memmove(Ptr,
- Source->Buffer,
- Source->Length);
- Ptr += Source->Length;
- *Ptr = 0;
+ RtlMoveMemory(&Destination->Buffer[Destination->Length],
+ Source->Buffer,
+ SourceLength);
- Destination->Length += Source->Length;
+ Destination->Length += SourceLength;
+ }
- return(STATUS_SUCCESS);
+ return STATUS_SUCCESS;
}
-
-
/*
* @implemented
*
* When dest fits exactly in MaximumLength characters the nullterm is ommitted.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlAppendUnicodeStringToString(
IN OUT PUNICODE_STRING Destination,
IN PCUNICODE_STRING Source)
{
+ USHORT SourceLength = Source->Length;
+ PWCHAR Buffer = &Destination->Buffer[Destination->Length / sizeof(WCHAR)];
- if ((Source->Length + Destination->Length) > Destination->MaximumLength)
- return STATUS_BUFFER_TOO_SMALL;
+ if (SourceLength)
+ {
+ if ((SourceLength+ Destination->Length) > Destination->MaximumLength)
+ {
+ return STATUS_BUFFER_TOO_SMALL;
+ }
- memcpy((char*)Destination->Buffer + Destination->Length, Source->Buffer, Source->Length);
- Destination->Length += Source->Length;
- /* append terminating '\0' if enough space */
- if( Destination->MaximumLength > Destination->Length )
- Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0;
+ RtlMoveMemory(Buffer, Source->Buffer, SourceLength);
+ Destination->Length += SourceLength;
- return STATUS_SUCCESS;
-}
+ /* append terminating '\0' if enough space */
+ if (Destination->MaximumLength > Destination->Length)
+ {
+ Buffer[SourceLength / sizeof(WCHAR)] = UNICODE_NULL;
+ }
+ }
+ return STATUS_SUCCESS;
+}
/**************************************************************************
* RtlCharToInteger (NTDLL.@)
* This function does not read garbage behind '\0' as the native version does.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlCharToInteger(
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) */
* @implemented
*/
LONG
-STDCALL
+NTAPI
RtlCompareString(
IN PSTRING s1,
IN PSTRING s2,
return ret;
}
-
/*
* @implemented
*
* TRUE if strings are equal.
*/
BOOLEAN
-STDCALL
+NTAPI
RtlEqualString(
IN PSTRING s1,
IN PSTRING s2,
IN BOOLEAN CaseInsensitive)
{
- if (s1->Length != s2->Length) return FALSE;
- return !RtlCompareString(s1, s2, CaseInsensitive );
+ if (s1->Length != s2->Length) return FALSE;
+ return !RtlCompareString(s1, s2, CaseInsensitive);
}
-
/*
* @implemented
*
* TRUE if strings are equal.
*/
BOOLEAN
-STDCALL
+NTAPI
RtlEqualUnicodeString(
IN CONST UNICODE_STRING *s1,
IN CONST UNICODE_STRING *s2,
IN BOOLEAN CaseInsensitive)
{
- if (s1->Length != s2->Length) return FALSE;
- return !RtlCompareUnicodeString((PUNICODE_STRING)s1, (PUNICODE_STRING)s2, CaseInsensitive );
+ if (s1->Length != s2->Length) return FALSE;
+ return !RtlCompareUnicodeString(s1, s2, CaseInsensitive );
}
-
/*
* @implemented
*/
VOID
-STDCALL
+NTAPI
RtlFreeAnsiString(IN PANSI_STRING AnsiString)
{
- if (AnsiString->Buffer != NULL)
- {
- RtlpFreeStringMemory(AnsiString->Buffer, TAG_ASTR);
+ PAGED_CODE_RTL();
- AnsiString->Buffer = NULL;
- AnsiString->Length = 0;
- AnsiString->MaximumLength = 0;
- }
+ if (AnsiString->Buffer)
+ {
+ RtlpFreeStringMemory(AnsiString->Buffer, TAG_ASTR);
+ RtlZeroMemory(AnsiString, sizeof(ANSI_STRING));
+ }
}
-
/*
* @implemented
*/
VOID
-STDCALL
+NTAPI
RtlFreeOemString(IN POEM_STRING OemString)
{
- if (OemString->Buffer != NULL)
- {
- RtlpFreeStringMemory(OemString->Buffer, TAG_OSTR);
+ PAGED_CODE_RTL();
- OemString->Buffer = NULL;
- OemString->Length = 0;
- OemString->MaximumLength = 0;
- }
+ if (OemString->Buffer) RtlpFreeStringMemory(OemString->Buffer, TAG_OSTR);
}
-
/*
* @implemented
*/
VOID
-STDCALL
+NTAPI
RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
{
- if (UnicodeString->Buffer != NULL)
- {
- RtlpFreeStringMemory(UnicodeString->Buffer, TAG_USTR);
+ PAGED_CODE_RTL();
- UnicodeString->Buffer = NULL;
- UnicodeString->Length = 0;
- UnicodeString->MaximumLength = 0;
- }
+ if (UnicodeString->Buffer)
+ {
+ RtlpFreeStringMemory(UnicodeString->Buffer, TAG_ASTR);
+ RtlZeroMemory(UnicodeString, sizeof(UNICODE_STRING));
+ }
}
/*
* @unimplemented
*/
BOOLEAN
-STDCALL
-RtlIsValidOemCharacter (
- IN PWCHAR Char
- )
+NTAPI
+RtlIsValidOemCharacter(IN PWCHAR Char)
{
- UNIMPLEMENTED;
- return FALSE;
+ UNIMPLEMENTED;
+ return FALSE;
}
/*
* If source is NULL the length of source is assumed to be 0.
*/
VOID
-STDCALL
+NTAPI
RtlInitAnsiString(IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString)
{
- ULONG DestSize;
-
- if (SourceString == NULL)
- {
- DestinationString->Length = 0;
- DestinationString->MaximumLength = 0;
- }
- else
- {
- DestSize = strlen ((const char *)SourceString);
- DestinationString->Length = DestSize;
- DestinationString->MaximumLength = DestSize + sizeof(CHAR);
- }
- DestinationString->Buffer = (PCHAR)SourceString;
-}
+ ULONG DestSize;
+ if(SourceString)
+ {
+ DestSize = strlen(SourceString);
+ DestinationString->Length = (USHORT)DestSize;
+ DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR);
+ }
+ else
+ {
+ DestinationString->Length = 0;
+ DestinationString->MaximumLength = 0;
+ }
+ DestinationString->Buffer = (PCHAR)SourceString;
+}
/*
* @implemented
* If source is NULL the length of source is assumed to be 0.
*/
VOID
-STDCALL
+NTAPI
RtlInitString(
IN OUT PSTRING DestinationString,
IN PCSZ SourceString)
{
- ULONG DestSize;
-
- if (SourceString == NULL)
- {
- DestinationString->Length = 0;
- DestinationString->MaximumLength = 0;
- }
- else
- {
- DestSize = strlen((const char *)SourceString);
- DestinationString->Length = DestSize;
- DestinationString->MaximumLength = DestSize + sizeof(CHAR);
- }
- DestinationString->Buffer = (PCHAR)SourceString;
+ RtlInitAnsiString(DestinationString, SourceString);
}
-
/*
* @implemented
*
* If source is NULL the length of source is assumed to be 0.
*/
VOID
-STDCALL
+NTAPI
RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString)
{
- ULONG DestSize;
+ ULONG DestSize;
- DPRINT("RtlInitUnicodeString(DestinationString 0x%p, SourceString 0x%p)\n",
- DestinationString,
- SourceString);
+ if(SourceString)
+ {
+ DestSize = wcslen(SourceString) * sizeof(WCHAR);
+ DestinationString->Length = (USHORT)DestSize;
+ DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
+ }
+ else
+ {
+ DestinationString->Length = 0;
+ DestinationString->MaximumLength = 0;
+ }
- if (SourceString == NULL)
- {
- DestinationString->Length = 0;
- DestinationString->MaximumLength = 0;
- }
- else
- {
- DestSize = wcslen((PWSTR)SourceString) * sizeof(WCHAR);
- DestinationString->Length = DestSize;
- DestinationString->MaximumLength = DestSize + sizeof(WCHAR);
- }
- DestinationString->Buffer = (PWSTR)SourceString;
+ DestinationString->Buffer = (PWCHAR)SourceString;
}
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS
+NTAPI
RtlInitUnicodeStringEx(OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString)
{
- ULONG Length;
+ ULONG DestSize;
- if (SourceString != NULL)
- {
- Length = wcslen(SourceString) * sizeof(WCHAR);
- if (Length > 0xFFFC)
- return STATUS_NAME_TOO_LONG;
-
- DestinationString->Length = Length;
- DestinationString->MaximumLength = Length + sizeof(WCHAR);
- DestinationString->Buffer = (PWSTR)SourceString;
- }
- else
- {
- DestinationString->Length = 0;
- DestinationString->MaximumLength = 0;
- DestinationString->Buffer = NULL;
- }
+ if(SourceString)
+ {
+ DestSize = wcslen(SourceString) * sizeof(WCHAR);
+ if (DestSize >= 0xFFFC) return STATUS_NAME_TOO_LONG;
+ DestinationString->Length = (USHORT)DestSize;
+ DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
+ }
+ else
+ {
+ DestinationString->Length = 0;
+ DestinationString->MaximumLength = 0;
+ }
- return STATUS_SUCCESS;
+ DestinationString->Buffer = (PWCHAR)SourceString;
+ return STATUS_SUCCESS;
}
/*
* When str fits exactly in length characters the nullterm is ommitted.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlIntegerToChar(
IN ULONG Value,
IN ULONG Base,
return STATUS_SUCCESS;
}
-
/*
* @implemented
*/
NTSTATUS
-STDCALL
+NTAPI
RtlIntegerToUnicode(
IN ULONG Value,
IN ULONG Base OPTIONAL,
return STATUS_SUCCESS;
}
-
-
/*
* @implemented
*/
NTSTATUS
-STDCALL
+NTAPI
RtlIntegerToUnicodeString(
- IN ULONG Value,
- IN ULONG Base, /* optional */
+ IN ULONG Value,
+ IN ULONG Base OPTIONAL,
IN OUT PUNICODE_STRING String)
{
- ANSI_STRING AnsiString;
- CHAR Buffer[33];
- NTSTATUS Status;
-
- Status = RtlIntegerToChar (Value,
- Base,
- sizeof(Buffer),
- Buffer);
- if (NT_SUCCESS(Status))
- {
- AnsiString.Buffer = Buffer;
- AnsiString.Length = strlen (Buffer);
- AnsiString.MaximumLength = sizeof(Buffer);
+ ANSI_STRING AnsiString;
+ CHAR Buffer[16];
+ NTSTATUS Status;
- Status = RtlAnsiStringToUnicodeString (String,
- &AnsiString,
- FALSE);
- }
+ Status = RtlIntegerToChar(Value, Base, sizeof(Buffer), Buffer);
+ if (NT_SUCCESS(Status))
+ {
+ AnsiString.Buffer = Buffer;
+ AnsiString.Length = (USHORT)strlen(Buffer);
+ AnsiString.MaximumLength = sizeof(Buffer);
- return Status;
-}
+ Status = RtlAnsiStringToUnicodeString(String, &AnsiString, FALSE);
+ }
+ return Status;
+}
/*
-* @implemented
-*/
+ * @implemented
+ */
NTSTATUS
-STDCALL
+NTAPI
RtlInt64ToUnicodeString (
- IN ULONGLONG Value,
- IN ULONG Base OPTIONAL,
- IN OUT PUNICODE_STRING String
- )
+ IN ULONGLONG Value,
+ IN ULONG Base OPTIONAL,
+ IN OUT PUNICODE_STRING String)
{
- LARGE_INTEGER LargeInt;
- ANSI_STRING AnsiString;
- CHAR Buffer[33];
- NTSTATUS Status;
-
- LargeInt.QuadPart = Value;
-
- Status = RtlLargeIntegerToChar (&LargeInt,
- Base,
- sizeof(Buffer),
- Buffer);
- if (NT_SUCCESS(Status))
- {
- AnsiString.Buffer = Buffer;
- AnsiString.Length = strlen (Buffer);
- AnsiString.MaximumLength = sizeof(Buffer);
+ LARGE_INTEGER LargeInt;
+ ANSI_STRING AnsiString;
+ CHAR Buffer[32];
+ NTSTATUS Status;
- Status = RtlAnsiStringToUnicodeString (String,
- &AnsiString,
- FALSE);
- }
+ LargeInt.QuadPart = Value;
- return Status;
-}
+ Status = RtlLargeIntegerToChar(&LargeInt, Base, sizeof(Buffer), Buffer);
+ if (NT_SUCCESS(Status))
+ {
+ AnsiString.Buffer = Buffer;
+ AnsiString.Length = (USHORT)strlen(Buffer);
+ AnsiString.MaximumLength = sizeof(Buffer);
+ Status = RtlAnsiStringToUnicodeString(String, &AnsiString, FALSE);
+ }
+
+ return Status;
+}
/*
* @implemented
* TRUE if String2 contains String1 as a prefix.
*/
BOOLEAN
-STDCALL
+NTAPI
RtlPrefixString(
PANSI_STRING String1,
PANSI_STRING String2,
return FALSE;
}
-
/*
* @implemented
*
* TRUE if String2 contains String1 as a prefix.
*/
BOOLEAN
-STDCALL
+NTAPI
RtlPrefixUnicodeString(
PCUNICODE_STRING String1,
PCUNICODE_STRING String2,
* version does.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUnicodeStringToInteger(
PCUNICODE_STRING str, /* [I] Unicode string to be converted */
ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
return STATUS_SUCCESS;
}
-
/*
* @implemented
*
* Bytes necessary for the conversion including nullterm.
*/
ULONG
-STDCALL
+NTAPI
RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString)
{
ULONG Size;
/*
* @implemented
*
-
* NOTES
* This function always writes a terminating '\0'.
* It performs a partial copy if ansi is too small.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUnicodeStringToAnsiString(
IN OUT PANSI_STRING AnsiDest,
IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG Length; /* including nullterm */
+ NTSTATUS Status = STATUS_SUCCESS;
+ NTSTATUS RealStatus;
+ ULONG Length;
+ ULONG Index;
- Length = RtlUnicodeStringToAnsiSize(UniSource);
- AnsiDest->Length = Length - sizeof(CHAR);
+ PAGED_CODE_RTL();
- if (AllocateDestinationString)
- {
- AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
- if (AnsiDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
+ Length = RtlUnicodeStringToAnsiSize(UniSource);
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
- AnsiDest->MaximumLength = Length;
- }
- else if (AnsiDest->MaximumLength == 0)
- {
- return STATUS_BUFFER_TOO_SMALL;
- }
- else if (Length > AnsiDest->MaximumLength)
- {
- /* make room for nullterm */
- AnsiDest->Length = AnsiDest->MaximumLength - sizeof(CHAR);
- }
+ AnsiDest->Length = (USHORT)Length - sizeof(CHAR);
- Status = RtlUnicodeToMultiByteN (AnsiDest->Buffer,
- AnsiDest->Length,
- NULL,
- UniSource->Buffer,
- UniSource->Length);
+ if (AllocateDestinationString)
+ {
+ AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
+ AnsiDest->MaximumLength = Length;
+ if (!AnsiDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (AnsiDest->Length >= AnsiDest->MaximumLength)
+ {
+ if (!AnsiDest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
- return Status;
- }
+ Status = STATUS_BUFFER_OVERFLOW;
+ AnsiDest->Length = AnsiDest->MaximumLength - 1;
+ }
- AnsiDest->Buffer[AnsiDest->Length] = 0;
- return Status;
-}
+ RealStatus = RtlUnicodeToMultiByteN(AnsiDest->Buffer,
+ AnsiDest->Length,
+ &Index,
+ UniSource->Buffer,
+ UniSource->Length);
+ if (!NT_SUCCESS(RealStatus) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
+ return RealStatus;
+ }
+
+ AnsiDest->Buffer[Index] = ANSI_NULL;
+ return Status;
+}
/*
* @implemented
* Does NOT perform a partial copy if unicode is too small!
*/
NTSTATUS
-STDCALL
+NTAPI
RtlOemStringToUnicodeString(
IN OUT PUNICODE_STRING UniDest,
IN PCOEM_STRING OemSource,
IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status;
- ULONG Length; /* including nullterm */
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
- Length = RtlOemStringToUnicodeSize(OemSource);
- if (Length > 0xffff)
- return STATUS_INVALID_PARAMETER_2;
+ PAGED_CODE_RTL();
- UniDest->Length = (WORD)(Length - sizeof(WCHAR));
+ Length = RtlOemStringToUnicodeSize(OemSource);
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
- if (AllocateDestinationString)
- {
- UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
- if (UniDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
+ UniDest->Length = (USHORT)Length - sizeof(WCHAR);
- UniDest->MaximumLength = Length;
- }
- else if (Length > UniDest->MaximumLength)
- {
- DPRINT("STATUS_BUFFER_TOO_SMALL\n");
- return STATUS_BUFFER_TOO_SMALL;
- }
-
- /* FIXME: Do we need this????? -Gunnar */
- RtlZeroMemory (UniDest->Buffer,
- UniDest->Length);
+ if (AllocateDestinationString)
+ {
+ UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
+ UniDest->MaximumLength = Length;
+ if (!UniDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (UniDest->Length >= UniDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- Status = RtlOemToUnicodeN (UniDest->Buffer,
+ Status = RtlOemToUnicodeN(UniDest->Buffer,
UniDest->Length,
- NULL,
+ &Index,
OemSource->Buffer,
OemSource->Length);
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
- return Status;
- }
+ if (!NT_SUCCESS(Status) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
+ UniDest->Buffer = NULL;
+ return Status;
+ }
- UniDest->Buffer[UniDest->Length / sizeof(WCHAR)] = 0;
- return STATUS_SUCCESS;
+ UniDest->Buffer[Index / sizeof(WCHAR)] = UNICODE_NULL;
+ return Status;
}
-
/*
* @implemented
*
* This function always '\0' terminates the string returned.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUnicodeStringToOemString(
IN OUT POEM_STRING OemDest,
IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG Length; //including nullterm
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
- Length = RtlUnicodeStringToAnsiSize(UniSource);
- if (Length > 0x0000FFFF)
- return STATUS_INVALID_PARAMETER_2;
+ PAGED_CODE_RTL();
- OemDest->Length = (WORD)(Length - sizeof(CHAR));
+ Length = RtlUnicodeStringToOemSize(UniSource);
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
- if (AllocateDestinationString)
- {
- OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
- if (OemDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
+ OemDest->Length = (USHORT)Length - sizeof(CHAR);
- OemDest->MaximumLength = Length;
- }
- else if (OemDest->MaximumLength == 0)
- {
- return STATUS_BUFFER_TOO_SMALL;
- }
- else if (Length > OemDest->MaximumLength)
- {
- //make room for nullterm
- OemDest->Length = OemDest->MaximumLength - sizeof(CHAR);
- }
+ if (AllocateDestinationString)
+ {
+ OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
+ OemDest->MaximumLength = Length;
+ if (!OemDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (OemDest->Length >= OemDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- Status = RtlUnicodeToOemN (OemDest->Buffer,
+ Status = RtlUnicodeToOemN(OemDest->Buffer,
OemDest->Length,
- NULL,
+ &Index,
UniSource->Buffer,
UniSource->Length);
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
- return Status;
- }
+ if (!NT_SUCCESS(Status) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
+ OemDest->Buffer = NULL;
+ return Status;
+ }
- OemDest->Buffer[OemDest->Length] = 0;
- return Status;
+ OemDest->Buffer[Index] = ANSI_NULL;
+ return Status;
}
#define ITU_IMPLEMENTED_TESTS (IS_TEXT_UNICODE_ODD_LENGTH|IS_TEXT_UNICODE_SIGNATURE)
-
/*
* @implemented
*
* RETURNS
* The length of the string if all tests were passed, 0 otherwise.
*/
-ULONG STDCALL
+ULONG NTAPI
RtlIsTextUnicode (PVOID Buffer,
ULONG Length,
ULONG *Flags)
return Length;
}
-
/*
* @implemented
*
* A partial copy is NOT performed if the dest buffer is too small!
*/
NTSTATUS
-STDCALL
+NTAPI
RtlOemStringToCountedUnicodeString(
IN OUT PUNICODE_STRING UniDest,
IN PCOEM_STRING OemSource,
IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status;
- ULONG Length; /* excluding nullterm */
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
- Length = RtlOemStringToCountedUnicodeSize(OemSource);
- if (Length > 65535)
- return STATUS_INVALID_PARAMETER_2;
+ PAGED_CODE_RTL();
- if (AllocateDestinationString == TRUE)
- {
- UniDest->Buffer = RtlpAllocateStringMemory (Length, TAG_USTR);
- if (UniDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
+ Length = RtlOemStringToCountedUnicodeSize(OemSource);
- UniDest->MaximumLength = Length;
- }
- else if (Length > UniDest->MaximumLength)
- {
- return STATUS_BUFFER_TOO_SMALL;
- }
+ if (!Length)
+ {
+ RtlZeroMemory(UniDest, sizeof(UNICODE_STRING));
+ return STATUS_SUCCESS;
+ }
+
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
+
+ UniDest->Length = (USHORT)Length;
- UniDest->Length = Length;
+ if (AllocateDestinationString)
+ {
+ UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
+ UniDest->MaximumLength = Length;
+ if (!UniDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (UniDest->Length >= UniDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- Status = RtlOemToUnicodeN (UniDest->Buffer,
+ Status = RtlOemToUnicodeN(UniDest->Buffer,
UniDest->Length,
- NULL,
+ &Index,
OemSource->Buffer,
OemSource->Length);
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
- return Status;
- }
+ if (!NT_SUCCESS(Status) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
+ UniDest->Buffer = NULL;
+ return Status;
+ }
- return Status;
+ return STATUS_SUCCESS;
}
/*
* The comparison is case insensitive.
*/
BOOLEAN
-STDCALL
+NTAPI
RtlEqualComputerName(
IN PUNICODE_STRING ComputerName1,
IN PUNICODE_STRING ComputerName2)
{
- OEM_STRING OemString1;
- OEM_STRING OemString2;
- BOOLEAN Result = FALSE;
+ OEM_STRING OemString1;
+ OEM_STRING OemString2;
+ BOOLEAN Result = FALSE;
- if (NT_SUCCESS(RtlUpcaseUnicodeStringToOemString( &OemString1, ComputerName1, TRUE )))
- {
- if (NT_SUCCESS(RtlUpcaseUnicodeStringToOemString( &OemString2, ComputerName2, TRUE )))
- {
- Result = RtlEqualString( &OemString1, &OemString2, TRUE );
- RtlFreeOemString( &OemString2 );
- }
- RtlFreeOemString( &OemString1 );
- }
+ if (NT_SUCCESS(RtlUpcaseUnicodeStringToOemString(&OemString1,
+ ComputerName1,
+ TRUE)))
+ {
+ if (NT_SUCCESS(RtlUpcaseUnicodeStringToOemString(&OemString2,
+ ComputerName2,
+ TRUE)))
+ {
+ Result = RtlEqualString(&OemString1, &OemString2, FALSE);
+ RtlFreeOemString(&OemString2);
+ }
+ RtlFreeOemString(&OemString1);
+ }
- return Result;
+ return Result;
}
/*
* The comparison is case insensitive.
*/
BOOLEAN
-STDCALL
+NTAPI
RtlEqualDomainName (
IN PUNICODE_STRING DomainName1,
IN PUNICODE_STRING DomainName2
)
{
- return RtlEqualComputerName(DomainName1, DomainName2);
+ return RtlEqualComputerName(DomainName1, DomainName2);
}
-
-/*
- * @implemented
- */
-/*
-BOOLEAN
-STDCALL
-RtlEqualDomainName (
- IN PUNICODE_STRING DomainName1,
- IN PUNICODE_STRING DomainName2
-)
-{
- 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;
-
-}
-*/
-
/*
* @implemented
*
* See RtlStringFromGUID.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlGUIDFromString(
IN UNICODE_STRING *str,
OUT GUID* guid
* @implemented
*/
VOID
-STDCALL
+NTAPI
RtlEraseUnicodeString(
IN PUNICODE_STRING String)
{
- if (String->Buffer != NULL &&
- String->MaximumLength != 0)
- {
- RtlZeroMemory (String->Buffer,
- String->MaximumLength);
-
- String->Length = 0;
- }
+ if (String->Buffer && String->MaximumLength)
+ {
+ RtlZeroMemory(String->Buffer, String->MaximumLength);
+ String->Length = 0;
+ }
}
/*
* @implemented
*/
NTSTATUS
-STDCALL
+NTAPI
RtlHashUnicodeString(
IN CONST UNICODE_STRING *String,
IN BOOLEAN CaseInSensitive,
* Does a partial copy if the dest buffer is too small
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUnicodeStringToCountedOemString(
IN OUT POEM_STRING OemDest,
IN PUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status;
- ULONG Length; //excluding nullterm
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
- Length = RtlUnicodeStringToCountedOemSize(UniSource);
- if (Length > 0x0000FFFF)
- return STATUS_INVALID_PARAMETER_2;
+ PAGED_CODE_RTL();
- OemDest->Length = (WORD)(Length);
+ Length = RtlUnicodeStringToCountedOemSize(UniSource);
- if (AllocateDestinationString)
- {
- OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
- if (OemDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
+ if (!Length)
+ {
+ RtlZeroMemory(OemDest, sizeof(UNICODE_STRING));
+ }
- OemDest->MaximumLength = Length;
- }
- else if (OemDest->MaximumLength == 0)
- {
- return STATUS_BUFFER_TOO_SMALL;
- }
- else if (Length > OemDest->MaximumLength)
- {
- OemDest->Length = OemDest->MaximumLength;
- }
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
+
+ OemDest->Length = (USHORT)Length;
+
+ if (AllocateDestinationString)
+ {
+ OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
+ OemDest->MaximumLength = Length;
+ if (!OemDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (OemDest->Length >= OemDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- Status = RtlUnicodeToOemN (OemDest->Buffer,
+ Status = RtlUnicodeToOemN(OemDest->Buffer,
OemDest->Length,
- NULL,
+ &Index,
UniSource->Buffer,
UniSource->Length);
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
- }
+ /* FIXME: Special check needed and return STATUS_UNMAPPABLE_CHARACTER */
+
+ if (!NT_SUCCESS(Status) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
+ OemDest->Buffer = NULL;
+ return Status;
+ }
- return Status;
+ return Status;
}
/*
* @implemented
*/
NTSTATUS
-STDCALL
+NTAPI
RtlLargeIntegerToChar(
IN PLARGE_INTEGER Value,
IN ULONG Base,
* might not be '\0' terminated. dest->Length is only set upon success.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUpcaseUnicodeString(
IN OUT PUNICODE_STRING UniDest,
IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
- ULONG i;
- PWCHAR Src, Dest;
+ ULONG i, j;
- if (AllocateDestinationString == TRUE)
- {
- UniDest->MaximumLength = UniSource->Length;
- UniDest->Buffer = RtlpAllocateStringMemory(UniDest->MaximumLength, TAG_USTR);
- if (UniDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
- }
- else if (UniSource->Length > UniDest->MaximumLength)
- {
- return STATUS_BUFFER_TOO_SMALL;
- }
+ PAGED_CODE_RTL();
+
+ if (AllocateDestinationString == TRUE)
+ {
+ UniDest->MaximumLength = UniSource->Length;
+ UniDest->Buffer = RtlpAllocateStringMemory(UniDest->MaximumLength, TAG_USTR);
+ if (UniDest->Buffer == NULL) return STATUS_NO_MEMORY;
+ }
+ else if (UniSource->Length > UniDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- UniDest->Length = UniSource->Length;
+ j = UniSource->Length / sizeof(WCHAR);
- Src = UniSource->Buffer;
- Dest = UniDest->Buffer;
- for (i = 0; i < UniSource->Length / sizeof(WCHAR); i++)
- {
- *Dest = RtlUpcaseUnicodeChar (*Src);
- Dest++;
- Src++;
- }
+ for (i = 0; i < j; i++)
+ {
+ UniDest->Buffer[i] = RtlUpcaseUnicodeChar(UniSource->Buffer[i]);
+ }
- return STATUS_SUCCESS;
+ UniDest->Length = UniSource->Length;
+ return STATUS_SUCCESS;
}
/*
* It performs a partial copy if ansi is too small.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUpcaseUnicodeStringToAnsiString(
IN OUT PANSI_STRING AnsiDest,
IN PUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status;
- ULONG Length; /* including nullterm */
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
- Length = RtlUnicodeStringToAnsiSize(UniSource);
- if (Length > 0x0000FFFF)
- return STATUS_INVALID_PARAMETER_2;
+ PAGED_CODE_RTL();
- AnsiDest->Length = (WORD)(Length - sizeof(CHAR));
+ Length = RtlUnicodeStringToAnsiSize(UniSource);
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
- if (AllocateDestinationString)
- {
- AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
- if (AnsiDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
+ AnsiDest->Length = (USHORT)Length - sizeof(CHAR);
- AnsiDest->MaximumLength = Length;
- }
- else if (AnsiDest->MaximumLength == 0)
- {
- return STATUS_BUFFER_TOO_SMALL;
- }
- else if (Length > AnsiDest->MaximumLength)
- {
- /* make room for nullterm */
- AnsiDest->Length = AnsiDest->MaximumLength - sizeof(CHAR);
- }
-
- /* FIXME: do we need this??????? -Gunnar */
- RtlZeroMemory (AnsiDest->Buffer,
- AnsiDest->Length);
+ if (AllocateDestinationString)
+ {
+ AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
+ AnsiDest->MaximumLength = Length;
+ if (!AnsiDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (AnsiDest->Length >= AnsiDest->MaximumLength)
+ {
+ if (!AnsiDest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
+ }
- Status = RtlUpcaseUnicodeToMultiByteN (AnsiDest->Buffer,
+ Status = RtlUpcaseUnicodeToMultiByteN(AnsiDest->Buffer,
AnsiDest->Length,
- NULL,
+ &Index,
UniSource->Buffer,
UniSource->Length);
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
- return Status;
- }
+ if (!NT_SUCCESS(Status) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
+ AnsiDest->Buffer = NULL;
+ return Status;
+ }
- AnsiDest->Buffer[AnsiDest->Length] = 0;
- return Status;
+ AnsiDest->Buffer[Index] = ANSI_NULL;
+ return Status;
}
/*
* It performs a partial copy if ansi is too small.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUpcaseUnicodeStringToCountedOemString(
IN OUT POEM_STRING OemDest,
IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status;
- ULONG Length; /* excluding nullterm */
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
- Length = RtlUnicodeStringToCountedOemSize(UniSource);
- if (Length > 0x0000FFFF)
- return(STATUS_INVALID_PARAMETER_2);
+ PAGED_CODE_RTL();
- OemDest->Length = (WORD)(Length);
+ Length = RtlUnicodeStringToCountedOemSize(UniSource);
- if (AllocateDestinationString)
- {
- OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
- if (OemDest->Buffer == NULL)
- return(STATUS_NO_MEMORY);
+ if (!Length)
+ {
+ RtlZeroMemory(OemDest, sizeof(UNICODE_STRING));
+ }
- /* FIXME: Do we need this????? */
- RtlZeroMemory (OemDest->Buffer, Length);
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
- OemDest->MaximumLength = (WORD)Length;
- }
- else if (OemDest->MaximumLength == 0)
- {
- return(STATUS_BUFFER_TOO_SMALL);
- }
- else if (Length > OemDest->MaximumLength)
- {
- OemDest->Length = OemDest->MaximumLength;
- }
+ OemDest->Length = (USHORT)Length;
- Status = RtlUpcaseUnicodeToOemN(OemDest->Buffer,
- OemDest->Length,
- NULL,
- UniSource->Buffer,
- UniSource->Length);
+ if (AllocateDestinationString)
+ {
+ OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
+ OemDest->MaximumLength = Length;
+ if (!OemDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (OemDest->Length >= OemDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
- return Status;
- }
+ Status = RtlUpcaseUnicodeToOemN(OemDest->Buffer,
+ OemDest->Length,
+ &Index,
+ UniSource->Buffer,
+ UniSource->Length);
+
+ /* FIXME: Special check needed and return STATUS_UNMAPPABLE_CHARACTER */
+
+ if (!NT_SUCCESS(Status) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
+ OemDest->Buffer = NULL;
+ return Status;
+ }
- return Status;
+ return Status;
}
/*
* It performs a partial copy if oem is too small.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlUpcaseUnicodeStringToOemString (
IN OUT POEM_STRING OemDest,
IN PCUNICODE_STRING UniSource,
- IN BOOLEAN AllocateDestinationString
-)
+ IN BOOLEAN AllocateDestinationString)
{
- NTSTATUS Status;
- ULONG Length; /* including nullterm */
-
- Length = RtlUnicodeStringToOemSize(UniSource);
- if (Length > 0x0000FFFF)
- return STATUS_INVALID_PARAMETER_2;
+ NTSTATUS Status;
+ ULONG Length;
+ ULONG Index;
- OemDest->Length = (WORD)(Length - sizeof(CHAR));
+ PAGED_CODE_RTL();
- if (AllocateDestinationString)
- {
- OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
- if (OemDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
+ Length = RtlUnicodeStringToOemSize(UniSource);
+ if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
- /* FIXME: Do we need this???? */
- RtlZeroMemory (OemDest->Buffer, Length);
+ OemDest->Length = (USHORT)Length - sizeof(CHAR);
- OemDest->MaximumLength = (WORD)Length;
- }
- else if (OemDest->MaximumLength == 0)
- {
- return STATUS_BUFFER_OVERFLOW;
- }
- else if (Length > OemDest->MaximumLength)
- {
- /* make room for nullterm */
- OemDest->Length = OemDest->MaximumLength - sizeof(CHAR);
- }
+ if (AllocateDestinationString)
+ {
+ OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
+ OemDest->MaximumLength = Length;
+ if (!OemDest->Buffer) return STATUS_NO_MEMORY;
+ }
+ else if (OemDest->Length >= OemDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- Status = RtlUpcaseUnicodeToOemN (OemDest->Buffer,
+ Status = RtlUpcaseUnicodeToOemN(OemDest->Buffer,
OemDest->Length,
- NULL,
+ &Index,
UniSource->Buffer,
UniSource->Length);
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
- return Status;
- }
+ /* FIXME: Special check needed and return STATUS_UNMAPPABLE_CHARACTER */
+
+ if (!NT_SUCCESS(Status) && AllocateDestinationString)
+ {
+ RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
+ OemDest->Buffer = NULL;
+ return Status;
+ }
- OemDest->Buffer[OemDest->Length] = 0;
- return Status;
+ OemDest->Buffer[Index] = ANSI_NULL;
+ return Status;
}
/*
* Bytes calculated including nullterm
*/
ULONG
-STDCALL
+NTAPI
RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString)
{
ULONG Size;
return (Size + sizeof(WCHAR));
}
-
-
/*
* @implemented
*/
NTSTATUS
-STDCALL
+NTAPI
RtlStringFromGUID (IN REFGUID Guid,
OUT PUNICODE_STRING GuidString)
{
- STATIC CONST PWCHAR Hex = L"0123456789ABCDEF";
+ static CONST PWCHAR Hex = L"0123456789ABCDEF";
WCHAR Buffer[40];
PWCHAR BufferPtr;
ULONG i;
return RtlCreateUnicodeString (GuidString, Buffer);
}
-
/*
* @implemented
*
* Bytes calculated including nullterm
*/
ULONG
-STDCALL
+NTAPI
RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString)
{
ULONG Size;
return (Size + sizeof(CHAR));
}
-
/*
* @implemented
*/
LONG
-STDCALL
+NTAPI
RtlCompareUnicodeString(
IN PCUNICODE_STRING s1,
IN PCUNICODE_STRING s2,
return ret;
}
-
-
/*
* @implemented
*/
VOID
-STDCALL
+NTAPI
RtlCopyString(
IN OUT PSTRING DestinationString,
- IN PSTRING SourceString)
+ IN PSTRING SourceString OPTIONAL)
{
- ULONG copylen;
+ ULONG SourceLength;
+ PCHAR p1, p2;
- if(SourceString == NULL)
- {
- DestinationString->Length = 0;
- return;
- }
-
- copylen = min (DestinationString->MaximumLength,
- SourceString->Length);
+ /* Check if there was no source given */
+ if(!SourceString)
+ {
+ /* Simply return an empty string */
+ DestinationString->Length = 0;
+ }
+ else
+ {
+ /* Choose the smallest length */
+ SourceLength = min(DestinationString->MaximumLength,
+ SourceString->Length);
- memcpy(DestinationString->Buffer, SourceString->Buffer, copylen);
- if (DestinationString->MaximumLength >= copylen + sizeof(CHAR))
- {
- DestinationString->Buffer[copylen] = 0;
- }
- DestinationString->Length = copylen;
-}
+ /* Set it */
+ DestinationString->Length = (USHORT)SourceLength;
+ /* Save the pointers to each buffer */
+ p1 = DestinationString->Buffer;
+ p2 = SourceString->Buffer;
+ /* Loop the buffer */
+ while (SourceLength)
+ {
+ /* Copy the character and move on */
+ *p1++ = * p2++;
+ SourceLength--;
+ }
+ }
+}
/*
* @implemented
*/
VOID
-STDCALL
+NTAPI
RtlCopyUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PCUNICODE_STRING SourceString)
{
- ULONG copylen;
+ ULONG SourceLength;
- if (SourceString == NULL)
- {
- DestinationString->Length = 0;
- return;
- }
+ if(SourceString == NULL)
+ {
+ DestinationString->Length = 0;
+ }
+ else
+ {
+ SourceLength = min(DestinationString->MaximumLength,
+ SourceString->Length);
+ DestinationString->Length = (USHORT)SourceLength;
- copylen = min (DestinationString->MaximumLength,
- SourceString->Length);
- memcpy(DestinationString->Buffer, SourceString->Buffer, copylen);
- if (DestinationString->MaximumLength >= copylen + sizeof(WCHAR))
- {
- DestinationString->Buffer[copylen / sizeof(WCHAR)] = 0;
- }
- DestinationString->Length = copylen;
+ RtlCopyMemory(DestinationString->Buffer,
+ SourceString->Buffer,
+ SourceLength);
+
+ if (DestinationString->Length < DestinationString->MaximumLength)
+ {
+ DestinationString->Buffer[SourceLength / sizeof(WCHAR)] = UNICODE_NULL;
+ }
+ }
}
/*
* Creates a nullterminated UNICODE_STRING
*/
BOOLEAN
-STDCALL
+NTAPI
RtlCreateUnicodeString(
IN OUT PUNICODE_STRING UniDest,
IN PCWSTR Source)
{
- ULONG Length;
+ ULONG Length;
- Length = (wcslen (Source) + 1) * sizeof(WCHAR);
- UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
- if (UniDest->Buffer == NULL)
- return FALSE;
+ PAGED_CODE_RTL();
+
+ Length = (wcslen(Source) + 1) * sizeof(WCHAR);
+ if (Length > 0xFFFE) return FALSE;
+
+ UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
- RtlCopyMemory (UniDest->Buffer,
- Source,
- Length);
+ if (UniDest->Buffer == NULL) return FALSE;
- UniDest->MaximumLength = Length;
- UniDest->Length = Length - sizeof (WCHAR);
+ RtlCopyMemory(UniDest->Buffer, Source, Length);
+ UniDest->MaximumLength = (USHORT)Length;
+ UniDest->Length = Length - sizeof (WCHAR);
- return TRUE;
+ return TRUE;
}
/*
* @implemented
*/
BOOLEAN
-STDCALL
+NTAPI
RtlCreateUnicodeStringFromAsciiz(
OUT PUNICODE_STRING Destination,
- IN PCSZ Source)
+ IN PCSZ Source)
{
- ANSI_STRING AnsiString;
- NTSTATUS Status;
+ ANSI_STRING AnsiString;
+ NTSTATUS Status;
- RtlInitAnsiString (&AnsiString,
- Source);
+ RtlInitAnsiString(&AnsiString, Source);
- Status = RtlAnsiStringToUnicodeString (Destination,
+ Status = RtlAnsiStringToUnicodeString(Destination,
&AnsiString,
TRUE);
- return NT_SUCCESS(Status);
+ return NT_SUCCESS(Status);
}
/*
* might not be '\0' terminated.
* Dest->Length is only set upon success.
*/
-NTSTATUS STDCALL
+NTSTATUS
+NTAPI
RtlDowncaseUnicodeString(
IN OUT PUNICODE_STRING UniDest,
IN PCUNICODE_STRING UniSource,
IN BOOLEAN AllocateDestinationString)
{
- ULONG i;
- PWCHAR Src, Dest;
+ ULONG i;
+ ULONG StopGap;
- if (AllocateDestinationString)
- {
- UniDest->Buffer = RtlpAllocateStringMemory(UniSource->Length, TAG_USTR);
- if (UniDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
-
- UniDest->MaximumLength = UniSource->Length;
- }
- else if (UniSource->Length > UniDest->MaximumLength)
- {
- return STATUS_BUFFER_TOO_SMALL;
- }
+ PAGED_CODE_RTL();
- UniDest->Length = UniSource->Length;
+ if (AllocateDestinationString)
+ {
+ UniDest->MaximumLength = UniSource->Length;
+ UniDest->Buffer = RtlpAllocateStringMemory(UniSource->Length, TAG_USTR);
+ if (UniDest->Buffer == NULL) return STATUS_NO_MEMORY;
+ }
+ else if (UniSource->Length > UniDest->MaximumLength)
+ {
+ return STATUS_BUFFER_OVERFLOW;
+ }
- Src = UniSource->Buffer;
- Dest = UniDest->Buffer;
- for (i=0; i < UniSource->Length / sizeof(WCHAR); i++)
- {
- if (*Src < L'A')
- {
- *Dest = *Src;
- }
- else if (*Src <= L'Z')
- {
- *Dest = (*Src + (L'a' - L'A'));
- }
- else
- {
- *Dest = RtlDowncaseUnicodeChar(*Src);
- }
+ UniDest->Length = UniSource->Length;
+ StopGap = UniSource->Length / sizeof(WCHAR);
- Dest++;
- Src++;
- }
+ for (i= 0 ; i < StopGap; i++)
+ {
+ if (UniSource->Buffer[i] < L'A')
+ {
+ UniDest->Buffer[i] = UniSource->Buffer[i];
+ }
+ else if (UniSource->Buffer[i] <= L'Z')
+ {
+ UniDest->Buffer[i] = (UniSource->Buffer[i] + (L'a' - L'A'));
+ }
+ else
+ {
+ UniDest->Buffer[i] = RtlDowncaseUnicodeChar(UniSource->Buffer[i]);
+ }
+ }
- return STATUS_SUCCESS;
+ return STATUS_SUCCESS;
}
/*
* dest is '\0' terminated when the MaximumLength allowes it.
* When dest fits exactly in MaximumLength characters the '\0' is ommitted.
*/
-NTSTATUS STDCALL
+NTSTATUS
+NTAPI
RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
IN PCWSTR Source)
{
- ULONG slen;
-
- slen = wcslen(Source) * sizeof(WCHAR);
-
- if (Destination->Length + slen > Destination->MaximumLength)
- return(STATUS_BUFFER_TOO_SMALL);
-
- memcpy((char*)Destination->Buffer + Destination->Length, Source, slen);
- Destination->Length += slen;
- /* append terminating '\0' if enough space */
- if( Destination->MaximumLength > Destination->Length )
- Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0;
-
- return(STATUS_SUCCESS);
-}
-
-/*
- * @implemented
- *
- * NOTES
- * This function always writes a terminating '\0'.
- * If the dest buffer is too small a partial copy is NOT performed!
- */
-NTSTATUS
-STDCALL
-RtlAnsiStringToUnicodeString(
- IN OUT PUNICODE_STRING UniDest,
- IN PANSI_STRING AnsiSource,
- IN BOOLEAN AllocateDestinationString)
-{
- NTSTATUS Status;
- ULONG Length; //including nullterm
-
- Length = RtlAnsiStringToUnicodeSize(AnsiSource);
- if (Length > 0xffff)
- return STATUS_INVALID_PARAMETER_2;
+ USHORT Length;
+ PWCHAR DestBuffer;
- if (AllocateDestinationString == TRUE)
- {
- UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
- if (UniDest->Buffer == NULL)
- return STATUS_NO_MEMORY;
-
- UniDest->MaximumLength = Length;
- }
- else if (Length > UniDest->MaximumLength)
- {
- DPRINT("STATUS_BUFFER_TOO_SMALL\n");
- return STATUS_BUFFER_TOO_SMALL;
- }
+ if (Source)
+ {
+ UNICODE_STRING UnicodeSource;
- UniDest->Length = Length - sizeof(WCHAR);
+ RtlInitUnicodeString(&UnicodeSource, Source);
+ Length = UnicodeSource.Length;
- //FIXME: We don't need this??? -Gunnar
- RtlZeroMemory (UniDest->Buffer,
- UniDest->Length);
+ if (Destination->Length + Length > Destination->MaximumLength)
+ {
+ return STATUS_BUFFER_TOO_SMALL;
+ }
- Status = RtlMultiByteToUnicodeN (UniDest->Buffer,
- UniDest->Length,
- NULL,
- AnsiSource->Buffer,
- AnsiSource->Length);
+ DestBuffer = &Destination->Buffer[Destination->Length / sizeof(WCHAR)];
+ RtlMoveMemory(DestBuffer, Source, Length);
+ Destination->Length += Length;
- if (!NT_SUCCESS(Status) && AllocateDestinationString)
- {
- RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
- return Status;
- }
+ /* append terminating '\0' if enough space */
+ if(Destination->MaximumLength > Destination->Length)
+ {
+ DestBuffer[Length / sizeof(WCHAR)] = UNICODE_NULL;
+ }
+ }
- UniDest->Buffer[UniDest->Length / sizeof(WCHAR)] = 0;
- return Status;
+ return STATUS_SUCCESS;
}
/*
* dest is never '\0' terminated.
*/
NTSTATUS
-STDCALL
+NTAPI
RtlAppendAsciizToString(
IN OUT PSTRING Destination,
IN PCSZ Source)
{
- ULONG Length;
- PCHAR Ptr;
+ ULONG Length;
- if (Source == NULL)
- return STATUS_SUCCESS;
-
- Length = strlen (Source);
- if (Destination->Length + Length >= Destination->MaximumLength)
- return STATUS_BUFFER_TOO_SMALL;
+ if (Source)
+ {
+ Length = (USHORT)strlen(Source);
- Ptr = Destination->Buffer + Destination->Length;
- memmove (Ptr,
- Source,
- Length);
- Ptr += Length;
- *Ptr = 0;
+ if (Destination->Length + Length > Destination->MaximumLength)
+ {
+ return STATUS_BUFFER_TOO_SMALL;
+ }
- Destination->Length += Length;
+ RtlMoveMemory(&Destination->Buffer[Destination->Length], Source, Length);
+ Destination->Length += Length;
+ }
- return STATUS_SUCCESS;
+ return STATUS_SUCCESS;
}
-
/*
* @implemented
*/
-VOID STDCALL
+VOID
+NTAPI
RtlUpperString(PSTRING DestinationString,
PSTRING SourceString)
{
- ULONG Length;
- ULONG i;
- PCHAR Src;
- PCHAR Dest;
-
- Length = min(SourceString->Length,
- DestinationString->MaximumLength - 1);
+ ULONG Length;
+ PCHAR Src, Dest;
- Src = SourceString->Buffer;
- Dest = DestinationString->Buffer;
- for (i = 0; i < Length; i++)
- {
- *Dest = RtlUpperChar(*Src);
- Src++;
- Dest++;
- }
- *Dest = 0;
+ Length = min(SourceString->Length,
+ DestinationString->MaximumLength - 1);
- DestinationString->Length = SourceString->Length;
+ Src = SourceString->Buffer;
+ Dest = DestinationString->Buffer;
+ DestinationString->Length = Length;
+ while (Length)
+ {
+ *Dest++ = RtlUpperChar(*Src++);
+ Length--;
+ }
}
/*
* See RtlpDuplicateUnicodeString
*/
NTSTATUS
-STDCALL
+NTAPI
RtlDuplicateUnicodeString(
IN ULONG Flags,
IN PCUNICODE_STRING SourceString,
OUT PUNICODE_STRING DestinationString)
{
+ PAGED_CODE_RTL();
+
if (SourceString == NULL || DestinationString == NULL)
return STATUS_INVALID_PARAMETER;
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
RtlValidateUnicodeString(IN ULONG Flags,
IN PUNICODE_STRING UnicodeString)
{