[MKHIVE]
[reactos.git] / reactos / tools / mkhive / rtl.c
index 7f4db5f..e9ed22b 100644 (file)
@@ -5,32 +5,17 @@
  */
 
 #include <stdlib.h>
+#include <stdarg.h>
 
-#define RTL_H
+/* gcc defaults to cdecl */
+#if defined(__GNUC__)
+#undef __cdecl
+#define __cdecl
+#endif
 
-#define NTOS_MODE_USER
-#define WIN32_NO_STATUS
-#include <ntddk.h>
+#include "mkhive.h"
 #include <bitmap.c>
 
-SIZE_T xwcslen( PCWSTR String ) {
-       SIZE_T i;
-
-       for( i = 0; String[i]; i++ );
-
-       return i;
-}
-
-PWSTR xwcschr( PWSTR String, WCHAR Char )
-{
-       SIZE_T i;
-
-       for( i = 0; String[i] && String[i] != Char; i++ );
-
-       if( String[i] ) return &String[i];
-       else return NULL;
-}
-
 /*
  * @implemented
  *
@@ -74,7 +59,7 @@ RtlInitUnicodeString(
 
        if(SourceString)
        {
-               DestSize = xwcslen(SourceString) * sizeof(WCHAR);
+               DestSize = utf16_wcslen(SourceString) * sizeof(WCHAR);
                DestinationString->Length = (USHORT)DestSize;
                DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
        }
@@ -143,7 +128,6 @@ VOID NTAPI
 KeQuerySystemTime(
        OUT PLARGE_INTEGER CurrentTime)
 {
-       DPRINT1("KeQuerySystemTime() unimplemented\n");
        CurrentTime->QuadPart = 0;
 }
 
@@ -162,3 +146,64 @@ 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;
+}