eec2fc3872e53f664c895d12d67cf4da45104704
[reactos.git] / reactos / tools / mkhive / rtl.c
1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS hive maker
3 * FILE: tools/mkhive/rtl.c
4 * PURPOSE: Runtime Library
5 */
6
7 #include <stdlib.h>
8 #include <stdarg.h>
9
10 #include "mkhive.h"
11 #include <bitmap.c>
12
13 /*
14 * @implemented
15 *
16 * NOTES
17 * If source is NULL the length of source is assumed to be 0.
18 */
19 VOID NTAPI
20 RtlInitAnsiString(
21 IN OUT PANSI_STRING DestinationString,
22 IN PCSTR SourceString)
23 {
24 SIZE_T DestSize;
25
26 if(SourceString)
27 {
28 DestSize = strlen(SourceString);
29 DestinationString->Length = (USHORT)DestSize;
30 DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR);
31 }
32 else
33 {
34 DestinationString->Length = 0;
35 DestinationString->MaximumLength = 0;
36 }
37
38 DestinationString->Buffer = (PCHAR)SourceString;
39 }
40
41 /*
42 * @implemented
43 *
44 * NOTES
45 * If source is NULL the length of source is assumed to be 0.
46 */
47 VOID NTAPI
48 RtlInitUnicodeString(
49 IN OUT PUNICODE_STRING DestinationString,
50 IN PCWSTR SourceString)
51 {
52 SIZE_T DestSize;
53
54 if(SourceString)
55 {
56 DestSize = utf16_wcslen(SourceString) * sizeof(WCHAR);
57 DestinationString->Length = (USHORT)DestSize;
58 DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
59 }
60 else
61 {
62 DestinationString->Length = 0;
63 DestinationString->MaximumLength = 0;
64 }
65
66 DestinationString->Buffer = (PWCHAR)SourceString;
67 }
68
69 NTSTATUS NTAPI
70 RtlAnsiStringToUnicodeString(
71 IN OUT PUNICODE_STRING UniDest,
72 IN PANSI_STRING AnsiSource,
73 IN BOOLEAN AllocateDestinationString)
74 {
75 ULONG Length;
76 PUCHAR WideString;
77 USHORT i;
78
79 Length = AnsiSource->Length * sizeof(WCHAR);
80 if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
81 UniDest->Length = (USHORT)Length;
82
83 if (AllocateDestinationString)
84 {
85 UniDest->MaximumLength = (USHORT)Length + sizeof(WCHAR);
86 UniDest->Buffer = (PWSTR) malloc(UniDest->MaximumLength);
87 if (!UniDest->Buffer)
88 return STATUS_NO_MEMORY;
89 }
90 else if (UniDest->Length >= UniDest->MaximumLength)
91 {
92 return STATUS_BUFFER_OVERFLOW;
93 }
94
95 WideString = (PUCHAR)UniDest->Buffer;
96 for (i = 0; i <= AnsiSource->Length; i++)
97 {
98 WideString[2 * i + 0] = AnsiSource->Buffer[i];
99 WideString[2 * i + 1] = 0;
100 }
101 return STATUS_SUCCESS;
102 }
103
104 WCHAR NTAPI
105 RtlUpcaseUnicodeChar(
106 IN WCHAR Source)
107 {
108 USHORT Offset;
109
110 if (Source < 'a')
111 return Source;
112
113 if (Source <= 'z')
114 return (Source - ('a' - 'A'));
115
116 Offset = 0;
117
118 return Source + (SHORT)Offset;
119 }
120
121 VOID NTAPI
122 KeQuerySystemTime(
123 OUT PLARGE_INTEGER CurrentTime)
124 {
125 CurrentTime->QuadPart = 0;
126 }
127
128 PVOID NTAPI
129 ExAllocatePool(
130 IN POOL_TYPE PoolType,
131 IN SIZE_T NumberOfBytes)
132 {
133 return (PVOID) malloc(NumberOfBytes);
134 }
135
136 VOID NTAPI
137 ExFreePool(
138 IN PVOID p)
139 {
140 free(p);
141 }
142
143 ULONG
144 __cdecl
145 DbgPrint(
146 IN CHAR *Format,
147 IN ...)
148 {
149 va_list ap;
150 va_start(ap, Format);
151 vprintf(Format, ap);
152 va_end(ap);
153
154 return 0;
155 }
156
157 VOID
158 NTAPI
159 RtlAssert(PVOID FailedAssertion,
160 PVOID FileName,
161 ULONG LineNumber,
162 PCHAR Message)
163 {
164 if (NULL != Message)
165 {
166 DbgPrint("Assertion \'%s\' failed at %s line %d: %s\n",
167 (PCHAR)FailedAssertion,
168 (PCHAR)FileName,
169 LineNumber,
170 Message);
171 }
172 else
173 {
174 DbgPrint("Assertion \'%s\' failed at %s line %d\n",
175 (PCHAR)FailedAssertion,
176 (PCHAR)FileName,
177 LineNumber);
178 }
179
180 //DbgBreakPoint();
181 }