[REACTOS] Fix 64 bit issues
[reactos.git] / sdk / tools / mkhive / rtl.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS hive maker
4 * FILE: tools/mkhive/rtl.c
5 * PURPOSE: Runtime Library
6 */
7
8 #include <stdlib.h>
9 #include <stdarg.h>
10
11 /* gcc defaults to cdecl */
12 #if defined(__GNUC__)
13 #undef __cdecl
14 #define __cdecl
15 #endif
16
17 #include "mkhive.h"
18 #include <bitmap.c>
19
20 /*
21 * @implemented
22 *
23 * NOTES
24 * If source is NULL the length of source is assumed to be 0.
25 */
26 VOID NTAPI
27 RtlInitUnicodeString(
28 IN OUT PUNICODE_STRING DestinationString,
29 IN PCWSTR SourceString)
30 {
31 SIZE_T DestSize;
32
33 if(SourceString)
34 {
35 DestSize = strlenW(SourceString) * sizeof(WCHAR);
36 DestinationString->Length = (USHORT)DestSize;
37 DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
38 }
39 else
40 {
41 DestinationString->Length = 0;
42 DestinationString->MaximumLength = 0;
43 }
44
45 DestinationString->Buffer = (PWCHAR)SourceString;
46 }
47
48 LONG NTAPI
49 RtlCompareUnicodeString(
50 IN PCUNICODE_STRING String1,
51 IN PCUNICODE_STRING String2,
52 IN BOOLEAN CaseInSensitive)
53 {
54 USHORT i;
55 WCHAR c1, c2;
56
57 for (i = 0; i <= String1->Length / sizeof(WCHAR) && i <= String2->Length / sizeof(WCHAR); i++)
58 {
59 if (CaseInSensitive)
60 {
61 c1 = RtlUpcaseUnicodeChar(String1->Buffer[i]);
62 c2 = RtlUpcaseUnicodeChar(String2->Buffer[i]);
63 }
64 else
65 {
66 c1 = String1->Buffer[i];
67 c2 = String2->Buffer[i];
68 }
69
70 if (c1 < c2)
71 return -1;
72 else if (c1 > c2)
73 return 1;
74 }
75
76 return 0;
77 }
78
79 WCHAR NTAPI
80 RtlUpcaseUnicodeChar(
81 IN WCHAR Source)
82 {
83 USHORT Offset;
84
85 if (Source < 'a')
86 return Source;
87
88 if (Source <= 'z')
89 return (Source - ('a' - 'A'));
90
91 Offset = 0;
92
93 return Source + (SHORT)Offset;
94 }
95
96 VOID NTAPI
97 KeQuerySystemTime(
98 OUT PLARGE_INTEGER CurrentTime)
99 {
100 CurrentTime->QuadPart = 0;
101 }
102
103 PVOID NTAPI
104 ExAllocatePool(
105 IN POOL_TYPE PoolType,
106 IN SIZE_T NumberOfBytes)
107 {
108 return (PVOID) malloc(NumberOfBytes);
109 }
110
111 VOID NTAPI
112 ExFreePool(
113 IN PVOID p)
114 {
115 free(p);
116 }
117
118 ULONG
119 __cdecl
120 DbgPrint(
121 IN CHAR *Format,
122 IN ...)
123 {
124 va_list ap;
125 va_start(ap, Format);
126 vprintf(Format, ap);
127 va_end(ap);
128
129 return 0;
130 }
131
132 VOID
133 NTAPI
134 RtlAssert(PVOID FailedAssertion,
135 PVOID FileName,
136 ULONG LineNumber,
137 PCHAR Message)
138 {
139 if (NULL != Message)
140 {
141 DbgPrint("Assertion \'%s\' failed at %s line %d: %s\n",
142 (PCHAR)FailedAssertion,
143 (PCHAR)FileName,
144 LineNumber,
145 Message);
146 }
147 else
148 {
149 DbgPrint("Assertion \'%s\' failed at %s line %d\n",
150 (PCHAR)FailedAssertion,
151 (PCHAR)FileName,
152 LineNumber);
153 }
154
155 //DbgBreakPoint();
156 }
157
158 // DECLSPEC_NORETURN
159 VOID
160 NTAPI
161 KeBugCheckEx(
162 IN ULONG BugCheckCode,
163 IN ULONG_PTR BugCheckParameter1,
164 IN ULONG_PTR BugCheckParameter2,
165 IN ULONG_PTR BugCheckParameter3,
166 IN ULONG_PTR BugCheckParameter4)
167 {
168 char Buffer[70];
169 printf("*** STOP: 0x%08X (0x%p,0x%p,0x%p,0x%p)",
170 BugCheckCode,
171 (PVOID)BugCheckParameter1,
172 (PVOID)BugCheckParameter2,
173 (PVOID)BugCheckParameter3,
174 (PVOID)BugCheckParameter4);
175 ASSERT(FALSE);
176 }
177
178 unsigned char BitScanForward(ULONG * Index, unsigned long Mask)
179 {
180 *Index = 0;
181 while (Mask && ((Mask & 1) == 0))
182 {
183 Mask >>= 1;
184 ++(*Index);
185 }
186 return Mask ? 1 : 0;
187 }
188
189 unsigned char BitScanReverse(ULONG * const Index, unsigned long Mask)
190 {
191 *Index = 0;
192 while (Mask && ((Mask & (1 << 31)) == 0))
193 {
194 Mask <<= 1;
195 ++(*Index);
196 }
197 return Mask ? 1 : 0;
198 }