- Don't use STATIC
[reactos.git] / reactos / lib / rtl / unicode.c
index ee64f36..a988c58 100644 (file)
@@ -27,24 +27,24 @@ extern PUSHORT NlsLeadByteInfo;
 * @implemented
 */
 WCHAR
-STDCALL
+NTAPI
 RtlAnsiCharToUnicodeChar(IN PUCHAR *AnsiChar)
 {
     ULONG Size;
     NTSTATUS Status;
-    WCHAR UnicodeChar = 0x20;
+    WCHAR UnicodeChar = L' ';
 
     Size = (NlsLeadByteInfo[**AnsiChar] == 0) ? 1 : 2;
 
     Status = RtlMultiByteToUnicodeN(&UnicodeChar,
                                     sizeof(WCHAR),
                                     NULL,
-                                    *AnsiChar,
+                                    (PCHAR)*AnsiChar,
                                     Size);
 
     if (!NT_SUCCESS(Status))
     {
-        UnicodeChar = 0x20;
+        UnicodeChar = L' ';
     }
 
     *AnsiChar += Size;
@@ -59,7 +59,7 @@ RtlAnsiCharToUnicodeChar(IN PUCHAR *AnsiChar)
  *  If the dest buffer is too small a partial copy is NOT performed!
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlAnsiStringToUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
    IN PANSI_STRING AnsiSource,
@@ -69,6 +69,8 @@ RtlAnsiStringToUnicodeString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlAnsiStringToUnicodeSize(AnsiSource);
     if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
     UniDest->Length = (USHORT)Length - sizeof(WCHAR);
@@ -107,7 +109,7 @@ RtlAnsiStringToUnicodeString(
  *  The calculated size in bytes including nullterm.
  */
 ULONG
-STDCALL
+NTAPI
 RtlxAnsiStringToUnicodeSize(IN PCANSI_STRING AnsiString)
 {
     ULONG Size;
@@ -129,7 +131,7 @@ RtlxAnsiStringToUnicodeSize(IN PCANSI_STRING AnsiString)
  *  Dest is never nullterminated.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlAppendStringToString(IN PSTRING Destination,
                         IN PSTRING Source)
 {
@@ -161,7 +163,7 @@ RtlAppendStringToString(IN PSTRING Destination,
  *  When dest fits exactly in MaximumLength characters the nullterm is ommitted.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlAppendUnicodeStringToString(
    IN OUT PUNICODE_STRING Destination,
    IN PCUNICODE_STRING Source)
@@ -211,7 +213,7 @@ RtlAppendUnicodeStringToString(
  *  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) */
@@ -283,7 +285,7 @@ RtlCharToInteger(
  * @implemented
  */
 LONG
-STDCALL
+NTAPI
 RtlCompareString(
    IN PSTRING s1,
    IN PSTRING s2,
@@ -316,7 +318,7 @@ RtlCompareString(
  *  TRUE if strings are equal.
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlEqualString(
    IN PSTRING s1,
    IN PSTRING s2,
@@ -333,7 +335,7 @@ RtlEqualString(
  *  TRUE if strings are equal.
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlEqualUnicodeString(
    IN CONST UNICODE_STRING *s1,
    IN CONST UNICODE_STRING *s2,
@@ -347,9 +349,11 @@ RtlEqualUnicodeString(
  * @implemented
  */
 VOID
-STDCALL
+NTAPI
 RtlFreeAnsiString(IN PANSI_STRING AnsiString)
 {
+    PAGED_CODE_RTL();
+
     if (AnsiString->Buffer)
     {
         RtlpFreeStringMemory(AnsiString->Buffer, TAG_ASTR);
@@ -361,9 +365,11 @@ RtlFreeAnsiString(IN PANSI_STRING AnsiString)
  * @implemented
  */
 VOID
-STDCALL
+NTAPI
 RtlFreeOemString(IN POEM_STRING OemString)
 {
+   PAGED_CODE_RTL();
+
    if (OemString->Buffer) RtlpFreeStringMemory(OemString->Buffer, TAG_OSTR);
 }
 
@@ -371,9 +377,11 @@ RtlFreeOemString(IN POEM_STRING OemString)
  * @implemented
  */
 VOID
-STDCALL
+NTAPI
 RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
 {
+    PAGED_CODE_RTL();
+
     if (UnicodeString->Buffer)
     {
         RtlpFreeStringMemory(UnicodeString->Buffer, TAG_ASTR);
@@ -385,7 +393,7 @@ RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
 * @unimplemented
 */
 BOOLEAN
-STDCALL
+NTAPI
 RtlIsValidOemCharacter(IN PWCHAR Char)
 {
     UNIMPLEMENTED;
@@ -399,7 +407,7 @@ RtlIsValidOemCharacter(IN PWCHAR Char)
  *  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)
 {
@@ -427,7 +435,7 @@ RtlInitAnsiString(IN OUT PANSI_STRING DestinationString,
  *  If source is NULL the length of source is assumed to be 0.
  */
 VOID
-STDCALL
+NTAPI
 RtlInitString(
    IN OUT PSTRING DestinationString,
    IN PCSZ SourceString)
@@ -442,7 +450,7 @@ RtlInitString(
  *  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)
 {
@@ -467,7 +475,7 @@ RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString,
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlInitUnicodeStringEx(OUT PUNICODE_STRING DestinationString,
                        IN PCWSTR SourceString)
 {
@@ -476,7 +484,7 @@ RtlInitUnicodeStringEx(OUT PUNICODE_STRING DestinationString,
     if(SourceString)
     {
         DestSize = wcslen(SourceString) * sizeof(WCHAR);
-        if (DestSize > 0xFFFC) return STATUS_NAME_TOO_LONG;
+        if (DestSize >= 0xFFFC) return STATUS_NAME_TOO_LONG;
         DestinationString->Length = (USHORT)DestSize;
         DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
     }
@@ -499,7 +507,7 @@ RtlInitUnicodeStringEx(OUT PUNICODE_STRING DestinationString,
  *  When str fits exactly in length characters the nullterm is ommitted.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlIntegerToChar(
    IN ULONG Value,
    IN ULONG Base,
@@ -552,7 +560,7 @@ RtlIntegerToChar(
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlIntegerToUnicode(
     IN ULONG Value,
     IN ULONG Base  OPTIONAL,
@@ -606,7 +614,7 @@ RtlIntegerToUnicode(
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlIntegerToUnicodeString(
    IN ULONG Value,
    IN ULONG Base OPTIONAL,
@@ -633,7 +641,7 @@ RtlIntegerToUnicodeString(
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlInt64ToUnicodeString (
     IN ULONGLONG Value,
     IN ULONG Base OPTIONAL,
@@ -666,7 +674,7 @@ RtlInt64ToUnicodeString (
  *  TRUE if String2 contains String1 as a prefix.
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlPrefixString(
    PANSI_STRING String1,
    PANSI_STRING String2,
@@ -713,7 +721,7 @@ RtlPrefixString(
  *  TRUE if String2 contains String1 as a prefix.
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlPrefixUnicodeString(
    PCUNICODE_STRING String1,
    PCUNICODE_STRING String2,
@@ -781,7 +789,7 @@ RtlPrefixUnicodeString(
  *  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) */
@@ -872,7 +880,7 @@ RtlUnicodeStringToInteger(
  *  Bytes necessary for the conversion including nullterm.
  */
 ULONG
-STDCALL
+NTAPI
 RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString)
 {
     ULONG Size;
@@ -894,7 +902,7 @@ RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString)
  *  It performs a partial copy if ansi is too small.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlUnicodeStringToAnsiString(
    IN OUT PANSI_STRING AnsiDest,
    IN PCUNICODE_STRING UniSource,
@@ -905,6 +913,8 @@ RtlUnicodeStringToAnsiString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlUnicodeStringToAnsiSize(UniSource);
     if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
 
@@ -948,7 +958,7 @@ RtlUnicodeStringToAnsiString(
  *  Does NOT perform a partial copy if unicode is too small!
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlOemStringToUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
    IN PCOEM_STRING OemSource,
@@ -958,6 +968,8 @@ RtlOemStringToUnicodeString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlOemStringToUnicodeSize(OemSource);
     if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
 
@@ -998,7 +1010,7 @@ RtlOemStringToUnicodeString(
  *   This function always '\0' terminates the string returned.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlUnicodeStringToOemString(
    IN OUT POEM_STRING OemDest,
    IN PCUNICODE_STRING UniSource,
@@ -1008,6 +1020,8 @@ RtlUnicodeStringToOemString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlUnicodeStringToOemSize(UniSource);
     if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
 
@@ -1049,7 +1063,7 @@ RtlUnicodeStringToOemString(
  * RETURNS
  *  The length of the string if all tests were passed, 0 otherwise.
  */
-ULONG STDCALL
+ULONG NTAPI
 RtlIsTextUnicode (PVOID Buffer,
                   ULONG Length,
                   ULONG *Flags)
@@ -1109,7 +1123,7 @@ done:
  *  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,
@@ -1119,6 +1133,8 @@ RtlOemStringToCountedUnicodeString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlOemStringToCountedUnicodeSize(OemSource);
 
     if (!Length)
@@ -1168,7 +1184,7 @@ RtlOemStringToCountedUnicodeString(
  *  The comparison is case insensitive.
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlEqualComputerName(
    IN PUNICODE_STRING ComputerName1,
    IN PUNICODE_STRING ComputerName2)
@@ -1204,7 +1220,7 @@ RtlEqualComputerName(
  *  The comparison is case insensitive.
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlEqualDomainName (
    IN PUNICODE_STRING DomainName1,
    IN PUNICODE_STRING DomainName2
@@ -1232,7 +1248,7 @@ RtlEqualDomainName (
  *  See RtlStringFromGUID.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlGUIDFromString(
    IN UNICODE_STRING *str,
    OUT GUID* guid
@@ -1346,7 +1362,7 @@ RtlGUIDFromString(
  * @implemented
  */
 VOID
-STDCALL
+NTAPI
 RtlEraseUnicodeString(
    IN PUNICODE_STRING String)
 {
@@ -1361,7 +1377,7 @@ RtlEraseUnicodeString(
 * @implemented
 */
 NTSTATUS
-STDCALL
+NTAPI
 RtlHashUnicodeString(
   IN CONST UNICODE_STRING *String,
   IN BOOLEAN CaseInSensitive,
@@ -1417,7 +1433,7 @@ RtlHashUnicodeString(
  *  Does a partial copy if the dest buffer is too small
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlUnicodeStringToCountedOemString(
    IN OUT POEM_STRING OemDest,
    IN PUNICODE_STRING UniSource,
@@ -1427,6 +1443,8 @@ RtlUnicodeStringToCountedOemString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlUnicodeStringToCountedOemSize(UniSource);
 
     if (!Length)
@@ -1471,7 +1489,7 @@ RtlUnicodeStringToCountedOemString(
  * @implemented
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlLargeIntegerToChar(
    IN PLARGE_INTEGER Value,
    IN ULONG  Base,
@@ -1524,7 +1542,7 @@ RtlLargeIntegerToChar(
  *  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,
@@ -1532,6 +1550,8 @@ RtlUpcaseUnicodeString(
 {
     ULONG i, j;
 
+    PAGED_CODE_RTL();
+
     if (AllocateDestinationString == TRUE)
     {
         UniDest->MaximumLength = UniSource->Length;
@@ -1562,7 +1582,7 @@ RtlUpcaseUnicodeString(
  *  It performs a partial copy if ansi is too small.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlUpcaseUnicodeStringToAnsiString(
    IN OUT PANSI_STRING AnsiDest,
    IN PUNICODE_STRING UniSource,
@@ -1572,6 +1592,8 @@ RtlUpcaseUnicodeStringToAnsiString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlUnicodeStringToAnsiSize(UniSource);
     if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
 
@@ -1613,7 +1635,7 @@ RtlUpcaseUnicodeStringToAnsiString(
  *  It performs a partial copy if ansi is too small.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlUpcaseUnicodeStringToCountedOemString(
    IN OUT POEM_STRING OemDest,
    IN PCUNICODE_STRING UniSource,
@@ -1623,6 +1645,8 @@ RtlUpcaseUnicodeStringToCountedOemString(
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlUnicodeStringToCountedOemSize(UniSource);
 
     if (!Length)
@@ -1670,7 +1694,7 @@ RtlUpcaseUnicodeStringToCountedOemString(
  *  It performs a partial copy if oem is too small.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlUpcaseUnicodeStringToOemString (
    IN OUT POEM_STRING OemDest,
    IN PCUNICODE_STRING UniSource,
@@ -1680,6 +1704,8 @@ RtlUpcaseUnicodeStringToOemString (
     ULONG Length;
     ULONG Index;
 
+    PAGED_CODE_RTL();
+
     Length = RtlUnicodeStringToOemSize(UniSource);
     if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
 
@@ -1722,7 +1748,7 @@ RtlUpcaseUnicodeStringToOemString (
  *  Bytes calculated including nullterm
  */
 ULONG
-STDCALL
+NTAPI
 RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString)
 {
     ULONG Size;
@@ -1740,11 +1766,11 @@ RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString)
  * @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;
@@ -1783,7 +1809,7 @@ RtlStringFromGUID (IN REFGUID Guid,
  *  Bytes calculated including nullterm
  */
 ULONG
-STDCALL
+NTAPI
 RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString)
 {
     ULONG Size;
@@ -1801,7 +1827,7 @@ RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString)
  * @implemented
  */
 LONG
-STDCALL
+NTAPI
 RtlCompareUnicodeString(
    IN PCUNICODE_STRING s1,
    IN PCUNICODE_STRING s2,
@@ -1831,7 +1857,7 @@ RtlCompareUnicodeString(
  * @implemented
  */
 VOID
-STDCALL
+NTAPI
 RtlCopyString(
    IN OUT PSTRING DestinationString,
    IN PSTRING SourceString OPTIONAL)
@@ -1872,7 +1898,7 @@ RtlCopyString(
  * @implemented
  */
 VOID
-STDCALL
+NTAPI
 RtlCopyUnicodeString(
    IN OUT PUNICODE_STRING DestinationString,
    IN PCUNICODE_STRING SourceString)
@@ -1907,19 +1933,23 @@ RtlCopyUnicodeString(
  * Creates a nullterminated UNICODE_STRING
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlCreateUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
    IN PCWSTR  Source)
 {
     ULONG Length;
 
+    PAGED_CODE_RTL();
+
     Length = (wcslen(Source) + 1) * sizeof(WCHAR);
+    if (Length > 0xFFFE) return FALSE;
+
     UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
 
     if (UniDest->Buffer == NULL) return FALSE;
 
-    RtlMoveMemory(UniDest->Buffer, Source, Length);
+    RtlCopyMemory(UniDest->Buffer, Source, Length);
     UniDest->MaximumLength = (USHORT)Length;
     UniDest->Length = Length - sizeof (WCHAR);
 
@@ -1930,7 +1960,7 @@ RtlCreateUnicodeString(
  * @implemented
  */
 BOOLEAN
-STDCALL
+NTAPI
 RtlCreateUnicodeStringFromAsciiz(
    OUT PUNICODE_STRING Destination,
    IN PCSZ Source)
@@ -1956,7 +1986,7 @@ RtlCreateUnicodeStringFromAsciiz(
  *  Dest->Length is only set upon success.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlDowncaseUnicodeString(
    IN OUT PUNICODE_STRING UniDest,
    IN PCUNICODE_STRING UniSource,
@@ -1965,6 +1995,8 @@ RtlDowncaseUnicodeString(
     ULONG i;
     ULONG StopGap;
 
+    PAGED_CODE_RTL();
+
     if (AllocateDestinationString)
     {
         UniDest->MaximumLength = UniSource->Length;
@@ -2007,7 +2039,7 @@ RtlDowncaseUnicodeString(
  *  When dest fits exactly in MaximumLength characters the '\0' is ommitted.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
                          IN PCWSTR Source)
 {
@@ -2048,7 +2080,7 @@ RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
  *  dest is never '\0' terminated.
  */
 NTSTATUS
-STDCALL
+NTAPI
 RtlAppendAsciizToString(
    IN OUT   PSTRING  Destination,
    IN PCSZ  Source)
@@ -2075,7 +2107,7 @@ RtlAppendAsciizToString(
  * @implemented
  */
 VOID
-STDCALL
+NTAPI
 RtlUpperString(PSTRING DestinationString,
                PSTRING SourceString)
 {
@@ -2102,12 +2134,14 @@ RtlUpperString(PSTRING DestinationString,
  *  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;
 
@@ -2145,7 +2179,7 @@ RtlDuplicateUnicodeString(
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 RtlValidateUnicodeString(IN ULONG Flags,
                          IN PUNICODE_STRING UnicodeString)
 {