[MKHIVE]
[reactos.git] / reactos / tools / mkhive / rtl.c
index 4ff2be3..a68d7a0 100644 (file)
@@ -4,11 +4,16 @@
  * PURPOSE:         Runtime Library
  */
 
-#define RTL_H
+#include <stdlib.h>
+#include <stdarg.h>
 
-#define NTOS_MODE_USER
-#define WIN32_NO_STATUS
-#include <ntddk.h>
+/* gcc defaults to cdecl */
+#if defined(__GNUC__)
+#undef __cdecl
+#define __cdecl
+#endif
+
+#include "mkhive.h"
 #include <bitmap.c>
 
 /*
@@ -54,7 +59,7 @@ RtlInitUnicodeString(
 
        if(SourceString)
        {
-               DestSize = wcslen(SourceString) * sizeof(WCHAR);
+               DestSize = utf16_wcslen(SourceString) * sizeof(WCHAR);
                DestinationString->Length = (USHORT)DestSize;
                DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
        }
@@ -84,7 +89,7 @@ RtlAnsiStringToUnicodeString(
        if (AllocateDestinationString)
        {
                UniDest->MaximumLength = (USHORT)Length + sizeof(WCHAR);
-               UniDest->Buffer = malloc(UniDest->MaximumLength);
+               UniDest->Buffer = (PWSTR) malloc(UniDest->MaximumLength);
                if (!UniDest->Buffer)
                        return STATUS_NO_MEMORY;
        }
@@ -123,7 +128,7 @@ VOID NTAPI
 KeQuerySystemTime(
        OUT PLARGE_INTEGER CurrentTime)
 {
-       DPRINT1("KeQuerySystemTime() unimplemented\n");
+       CurrentTime->QuadPart = 0;
 }
 
 PVOID NTAPI
@@ -131,7 +136,7 @@ ExAllocatePool(
        IN POOL_TYPE PoolType,
        IN SIZE_T NumberOfBytes)
 {
-       return malloc(NumberOfBytes);
+       return (PVOID) malloc(NumberOfBytes);
 }
 
 VOID NTAPI
@@ -141,3 +146,93 @@ ExFreePool(
        free(p);
 }
 
+ULONG
+__cdecl
+DbgPrint(
+  IN CHAR *Format,
+  IN ...)
+{
+    va_list ap;
+    va_start(ap, Format);
+    vprintf(Format, ap);
+    va_end(ap);
+
+    return 0;
+}
+
+VOID
+NTAPI
+RtlAssert(PVOID FailedAssertion,
+          PVOID FileName,
+          ULONG LineNumber,
+          PCHAR Message)
+{
+   if (NULL != Message)
+   {
+      DbgPrint("Assertion \'%s\' failed at %s line %d: %s\n",
+               (PCHAR)FailedAssertion,
+               (PCHAR)FileName,
+               LineNumber,
+               Message);
+   }
+   else
+   {
+      DbgPrint("Assertion \'%s\' failed at %s line %d\n",
+               (PCHAR)FailedAssertion,
+               (PCHAR)FileName,
+               LineNumber);
+   }
+
+   //DbgBreakPoint();
+}
+
+unsigned char BitScanForward(ULONG * Index, unsigned long Mask)
+{
+    *Index = 0;
+    while (Mask && ((Mask & 1) == 0))
+    {
+        Mask >>= 1;
+        ++(*Index);
+    }
+    return Mask ? 1 : 0;
+}
+
+unsigned char BitScanReverse(ULONG * const Index, unsigned long Mask)
+{
+    *Index = 0;
+    while (Mask && ((Mask & (1 << 31)) == 0))
+    {
+        Mask <<= 1;
+        ++(*Index);
+    }
+    return Mask ? 1 : 0;
+}
+
+#undef tolower
+WCHAR towlower(WCHAR ch)
+{
+    if (ch < L'A')
+    {
+        return ch;
+    }
+    else if (ch <= L'Z')
+    {
+        return ch + (L'a' - L'A');
+    }
+
+    return ch;
+}
+
+int _wcsicmp(PCWSTR cs, PCWSTR ct)
+{
+    while (towlower(*cs) == towlower(*ct))
+    {
+        if (*cs == 0)
+            return 0;
+
+        cs++;
+        ct++;
+    }
+
+    return towlower(*cs) - towlower(*ct);
+}