1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS hive maker
3 * FILE: tools/mkhive/rtl.c
4 * PURPOSE: Runtime Library
10 /* gcc defaults to cdecl */
23 * If source is NULL the length of source is assumed to be 0.
27 IN OUT PANSI_STRING DestinationString
,
28 IN PCSTR SourceString
)
34 DestSize
= strlen(SourceString
);
35 DestinationString
->Length
= (USHORT
)DestSize
;
36 DestinationString
->MaximumLength
= (USHORT
)DestSize
+ sizeof(CHAR
);
40 DestinationString
->Length
= 0;
41 DestinationString
->MaximumLength
= 0;
44 DestinationString
->Buffer
= (PCHAR
)SourceString
;
51 * If source is NULL the length of source is assumed to be 0.
55 IN OUT PUNICODE_STRING DestinationString
,
56 IN PCWSTR SourceString
)
62 DestSize
= utf16_wcslen(SourceString
) * sizeof(WCHAR
);
63 DestinationString
->Length
= (USHORT
)DestSize
;
64 DestinationString
->MaximumLength
= (USHORT
)DestSize
+ sizeof(WCHAR
);
68 DestinationString
->Length
= 0;
69 DestinationString
->MaximumLength
= 0;
72 DestinationString
->Buffer
= (PWCHAR
)SourceString
;
76 RtlAnsiStringToUnicodeString(
77 IN OUT PUNICODE_STRING UniDest
,
78 IN PANSI_STRING AnsiSource
,
79 IN BOOLEAN AllocateDestinationString
)
85 Length
= AnsiSource
->Length
* sizeof(WCHAR
);
86 if (Length
> MAXUSHORT
) return STATUS_INVALID_PARAMETER_2
;
87 UniDest
->Length
= (USHORT
)Length
;
89 if (AllocateDestinationString
)
91 UniDest
->MaximumLength
= (USHORT
)Length
+ sizeof(WCHAR
);
92 UniDest
->Buffer
= (PWSTR
) malloc(UniDest
->MaximumLength
);
94 return STATUS_NO_MEMORY
;
96 else if (UniDest
->Length
>= UniDest
->MaximumLength
)
98 return STATUS_BUFFER_OVERFLOW
;
101 WideString
= (PUCHAR
)UniDest
->Buffer
;
102 for (i
= 0; i
<= AnsiSource
->Length
; i
++)
104 WideString
[2 * i
+ 0] = AnsiSource
->Buffer
[i
];
105 WideString
[2 * i
+ 1] = 0;
107 return STATUS_SUCCESS
;
111 RtlUpcaseUnicodeChar(
120 return (Source
- ('a' - 'A'));
124 return Source
+ (SHORT
)Offset
;
129 OUT PLARGE_INTEGER CurrentTime
)
131 CurrentTime
->QuadPart
= 0;
136 IN POOL_TYPE PoolType
,
137 IN SIZE_T NumberOfBytes
)
139 return (PVOID
) malloc(NumberOfBytes
);
156 va_start(ap
, Format
);
165 RtlAssert(PVOID FailedAssertion
,
172 DbgPrint("Assertion \'%s\' failed at %s line %d: %s\n",
173 (PCHAR
)FailedAssertion
,
180 DbgPrint("Assertion \'%s\' failed at %s line %d\n",
181 (PCHAR
)FailedAssertion
,
189 unsigned char BitScanForward(ULONG
* Index
, unsigned long Mask
)
192 while (Mask
&& ((Mask
& 1) == 0))
200 unsigned char BitScanReverse(ULONG
* const Index
, unsigned long Mask
)
203 while (Mask
&& ((Mask
& (1 << 31)) == 0))