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