2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS hive maker
4 * FILE: tools/mkhive/rtl.c
5 * PURPOSE: Runtime Library
11 /* gcc defaults to cdecl */
24 * If source is NULL the length of source is assumed to be 0.
28 IN OUT PANSI_STRING DestinationString
,
29 IN PCSTR SourceString
)
35 DestSize
= strlen(SourceString
);
36 DestinationString
->Length
= (USHORT
)DestSize
;
37 DestinationString
->MaximumLength
= (USHORT
)DestSize
+ sizeof(CHAR
);
41 DestinationString
->Length
= 0;
42 DestinationString
->MaximumLength
= 0;
45 DestinationString
->Buffer
= (PCHAR
)SourceString
;
52 * If source is NULL the length of source is assumed to be 0.
56 IN OUT PUNICODE_STRING DestinationString
,
57 IN PCWSTR SourceString
)
63 DestSize
= strlenW(SourceString
) * sizeof(WCHAR
);
64 DestinationString
->Length
= (USHORT
)DestSize
;
65 DestinationString
->MaximumLength
= (USHORT
)DestSize
+ sizeof(WCHAR
);
69 DestinationString
->Length
= 0;
70 DestinationString
->MaximumLength
= 0;
73 DestinationString
->Buffer
= (PWCHAR
)SourceString
;
77 RtlAnsiStringToUnicodeString(
78 IN OUT PUNICODE_STRING UniDest
,
79 IN PANSI_STRING AnsiSource
,
80 IN BOOLEAN AllocateDestinationString
)
86 Length
= AnsiSource
->Length
* sizeof(WCHAR
);
87 if (Length
> MAXUSHORT
) return STATUS_INVALID_PARAMETER_2
;
88 UniDest
->Length
= (USHORT
)Length
;
90 if (AllocateDestinationString
)
92 UniDest
->MaximumLength
= (USHORT
)Length
+ sizeof(WCHAR
);
93 UniDest
->Buffer
= (PWSTR
) malloc(UniDest
->MaximumLength
);
95 return STATUS_NO_MEMORY
;
97 else if (UniDest
->Length
>= UniDest
->MaximumLength
)
99 return STATUS_BUFFER_OVERFLOW
;
102 WideString
= (PUCHAR
)UniDest
->Buffer
;
103 for (i
= 0; i
<= AnsiSource
->Length
; i
++)
105 WideString
[2 * i
+ 0] = AnsiSource
->Buffer
[i
];
106 WideString
[2 * i
+ 1] = 0;
108 return STATUS_SUCCESS
;
112 RtlCompareUnicodeString(
113 IN PCUNICODE_STRING String1
,
114 IN PCUNICODE_STRING String2
,
115 IN BOOLEAN CaseInSensitive
)
120 for (i
= 0; i
<= String1
->Length
/ sizeof(WCHAR
) && i
<= String2
->Length
/ sizeof(WCHAR
); i
++)
124 c1
= RtlUpcaseUnicodeChar(String1
->Buffer
[i
]);
125 c2
= RtlUpcaseUnicodeChar(String2
->Buffer
[i
]);
129 c1
= String1
->Buffer
[i
];
130 c2
= String2
->Buffer
[i
];
143 RtlUpcaseUnicodeChar(
152 return (Source
- ('a' - 'A'));
156 return Source
+ (SHORT
)Offset
;
161 OUT PLARGE_INTEGER CurrentTime
)
163 CurrentTime
->QuadPart
= 0;
168 IN POOL_TYPE PoolType
,
169 IN SIZE_T NumberOfBytes
)
171 return (PVOID
) malloc(NumberOfBytes
);
188 va_start(ap
, Format
);
197 RtlAssert(PVOID FailedAssertion
,
204 DbgPrint("Assertion \'%s\' failed at %s line %d: %s\n",
205 (PCHAR
)FailedAssertion
,
212 DbgPrint("Assertion \'%s\' failed at %s line %d\n",
213 (PCHAR
)FailedAssertion
,
225 IN ULONG BugCheckCode
,
226 IN ULONG_PTR BugCheckParameter1
,
227 IN ULONG_PTR BugCheckParameter2
,
228 IN ULONG_PTR BugCheckParameter3
,
229 IN ULONG_PTR BugCheckParameter4
)
232 printf("*** STOP: 0x%08lX (0x%08lX, 0x%08lX, 0x%08lX, 0x%08lX)",
233 BugCheckCode
, BugCheckParameter1
, BugCheckParameter2
,
234 BugCheckParameter3
, BugCheckParameter4
);
238 unsigned char BitScanForward(ULONG
* Index
, unsigned long Mask
)
241 while (Mask
&& ((Mask
& 1) == 0))
249 unsigned char BitScanReverse(ULONG
* const Index
, unsigned long Mask
)
252 while (Mask
&& ((Mask
& (1 << 31)) == 0))