Fix mkhive on unix.
[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 #define RTL_H
8
9 #define NTOS_MODE_USER
10 #define WIN32_NO_STATUS
11 #include <ntddk.h>
12 #include <bitmap.c>
13
14 SIZE_T xwcslen( PWSTR String ) {
15 SIZE_T i;
16
17 for( i = 0; String[i]; i++ );
18
19 return i;
20 }
21
22 PWSTR xwcschr( PWSTR String, WCHAR Char )
23 {
24 SIZE_T i;
25
26 for( i = 0; String[i] && String[i] != Char; i++ );
27
28 if( String[i] ) return &String[i];
29 else return NULL;
30 }
31
32 /*
33 * @implemented
34 *
35 * NOTES
36 * If source is NULL the length of source is assumed to be 0.
37 */
38 VOID NTAPI
39 RtlInitAnsiString(
40 IN OUT PANSI_STRING DestinationString,
41 IN PCSTR SourceString)
42 {
43 SIZE_T DestSize;
44
45 if(SourceString)
46 {
47 DestSize = strlen(SourceString);
48 DestinationString->Length = (USHORT)DestSize;
49 DestinationString->MaximumLength = (USHORT)DestSize + sizeof(CHAR);
50 }
51 else
52 {
53 DestinationString->Length = 0;
54 DestinationString->MaximumLength = 0;
55 }
56
57 DestinationString->Buffer = (PCHAR)SourceString;
58 }
59
60 /*
61 * @implemented
62 *
63 * NOTES
64 * If source is NULL the length of source is assumed to be 0.
65 */
66 VOID NTAPI
67 RtlInitUnicodeString(
68 IN OUT PUNICODE_STRING DestinationString,
69 IN PCWSTR SourceString)
70 {
71 SIZE_T DestSize;
72
73 if(SourceString)
74 {
75 DestSize = xwcslen(SourceString) * sizeof(WCHAR);
76 DestinationString->Length = (USHORT)DestSize;
77 DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
78 }
79 else
80 {
81 DestinationString->Length = 0;
82 DestinationString->MaximumLength = 0;
83 }
84
85 DestinationString->Buffer = (PWCHAR)SourceString;
86 }
87
88 NTSTATUS NTAPI
89 RtlAnsiStringToUnicodeString(
90 IN OUT PUNICODE_STRING UniDest,
91 IN PANSI_STRING AnsiSource,
92 IN BOOLEAN AllocateDestinationString)
93 {
94 ULONG Length;
95 PUCHAR WideString;
96 USHORT i;
97
98 Length = AnsiSource->Length * sizeof(WCHAR);
99 if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
100 UniDest->Length = (USHORT)Length;
101
102 if (AllocateDestinationString)
103 {
104 UniDest->MaximumLength = (USHORT)Length + sizeof(WCHAR);
105 UniDest->Buffer = (PWSTR) malloc(UniDest->MaximumLength);
106 if (!UniDest->Buffer)
107 return STATUS_NO_MEMORY;
108 }
109 else if (UniDest->Length >= UniDest->MaximumLength)
110 {
111 return STATUS_BUFFER_OVERFLOW;
112 }
113
114 WideString = (PUCHAR)UniDest->Buffer;
115 for (i = 0; i <= AnsiSource->Length; i++)
116 {
117 WideString[2 * i + 0] = AnsiSource->Buffer[i];
118 WideString[2 * i + 1] = 0;
119 }
120 return STATUS_SUCCESS;
121 }
122
123 WCHAR NTAPI
124 RtlUpcaseUnicodeChar(
125 IN WCHAR Source)
126 {
127 USHORT Offset;
128
129 if (Source < 'a')
130 return Source;
131
132 if (Source <= 'z')
133 return (Source - ('a' - 'A'));
134
135 Offset = 0;
136
137 return Source + (SHORT)Offset;
138 }
139
140 VOID NTAPI
141 KeQuerySystemTime(
142 OUT PLARGE_INTEGER CurrentTime)
143 {
144 DPRINT1("KeQuerySystemTime() unimplemented\n");
145 }
146
147 PVOID NTAPI
148 ExAllocatePool(
149 IN POOL_TYPE PoolType,
150 IN SIZE_T NumberOfBytes)
151 {
152 return (PVOID) malloc(NumberOfBytes);
153 }
154
155 VOID NTAPI
156 ExFreePool(
157 IN PVOID p)
158 {
159 free(p);
160 }
161