4 * Copyright 1996-1998 Marcus Meissner
15 #include "wine/winestring.h"
19 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(ntdll)
28 /**************************************************************************
29 * RtlAnsiStringToUnicodeString [NTDLL.269]
32 WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING uni,PANSI_STRING ansi,BOOLEAN doalloc)
34 DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
37 return STATUS_INVALID_PARAMETER_2;
40 uni->MaximumLength = unilen;
41 uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
43 return STATUS_NO_MEMORY;
45 if (unilen>uni->MaximumLength)
46 return STATUS_BUFFER_OVERFLOW;
47 lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
48 return STATUS_SUCCESS;
51 /**************************************************************************
52 * RtlOemStringToUnicodeString [NTDLL.447]
55 WINAPI RtlOemStringToUnicodeString(PUNICODE_STRING uni,PSTRING ansi,BOOLEAN doalloc)
57 DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
60 return STATUS_INVALID_PARAMETER_2;
63 uni->MaximumLength = unilen;
64 uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
66 return STATUS_NO_MEMORY;
68 if (unilen>uni->MaximumLength)
69 return STATUS_BUFFER_OVERFLOW;
70 lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
71 return STATUS_SUCCESS;
73 /**************************************************************************
74 * RtlMultiByteToUnicodeN [NTDLL.436]
75 * FIXME: multibyte support
78 WINAPI RtlMultiByteToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
86 x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
87 lstrcpynAtoW(x,oemstr,len+1);
88 memcpy(unistr,x,len*2);
89 if (reslen) *reslen = len*2;
93 /**************************************************************************
94 * RtlOemToUnicodeN [NTDLL.448]
97 WINAPI RtlOemToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
105 x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
106 lstrcpynAtoW(x,oemstr,len+1);
107 memcpy(unistr,x,len*2);
108 if (reslen) *reslen = len*2;
112 /**************************************************************************
113 * RtlInitAnsiString [NTDLL.399]
115 VOID WINAPI RtlInitAnsiString(PANSI_STRING target,LPCSTR source)
117 target->Length = target->MaximumLength = 0;
118 target->Buffer = (LPSTR)source;
121 target->MaximumLength = lstrlenA(target->Buffer);
122 target->Length = target->MaximumLength+1;
124 /**************************************************************************
125 * RtlInitString [NTDLL.402]
127 VOID WINAPI RtlInitString(PSTRING target,LPCSTR source)
129 target->Length = target->MaximumLength = 0;
130 target->Buffer = (LPSTR)source;
133 target->MaximumLength = lstrlenA(target->Buffer);
134 target->Length = target->MaximumLength+1;
137 /**************************************************************************
138 * RtlInitUnicodeString [NTDLL.403]
140 VOID WINAPI RtlInitUnicodeString(PUNICODE_STRING target,LPCWSTR source)
142 TRACE("%p %p(%s)\n", target, source, debugstr_w(source));
144 target->Length = target->MaximumLength = 0;
145 target->Buffer = (LPWSTR)source;
148 target->MaximumLength = lstrlenW(target->Buffer)*2;
149 target->Length = target->MaximumLength+2;
152 /**************************************************************************
153 * RtlFreeUnicodeString [NTDLL.377]
155 VOID WINAPI RtlFreeUnicodeString(PUNICODE_STRING str)
158 HeapFree(GetProcessHeap(),0,str->Buffer);
161 /**************************************************************************
162 * RtlFreeAnsiString [NTDLL.373]
164 VOID WINAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
166 if( AnsiString->Buffer )
167 HeapFree( GetProcessHeap(),0,AnsiString->Buffer );
171 /**************************************************************************
172 * RtlUnicodeToOemN [NTDLL.515]
175 WINAPI RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,DWORD unilen)
183 x=(LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+1);
184 lstrcpynWtoA(x,unistr,len+1);
185 memcpy(oemstr,x,len);
186 if (reslen) *reslen = len;
190 /**************************************************************************
191 * RtlUnicodeStringToOemString [NTDLL.511]
194 WINAPI RtlUnicodeStringToOemString(PANSI_STRING oem,PUNICODE_STRING uni,BOOLEAN alloc)
197 oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
198 oem->MaximumLength = uni->Length/2+1;
200 oem->Length = uni->Length/2;
201 lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
205 /**************************************************************************
206 * RtlUnicodeStringToAnsiString [NTDLL.507]
209 WINAPI RtlUnicodeStringToAnsiString(PANSI_STRING oem,PUNICODE_STRING uni,BOOLEAN alloc)
212 oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
213 oem->MaximumLength = uni->Length/2+1;
215 oem->Length = uni->Length/2;
216 lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
220 /**************************************************************************
221 * RtlEqualUnicodeString [NTDLL]
223 DWORD WINAPI RtlEqualUnicodeString(PUNICODE_STRING s1,PUNICODE_STRING s2,DWORD x) {
224 FIXME("(%s,%s,%ld),stub!\n",debugstr_w(s1->Buffer),debugstr_w(s2->Buffer),x);
226 if (s1->Length != s2->Length)
228 return !CRTDLL_wcsncmp(s1->Buffer,s2->Buffer,s1->Length/2);
231 /**************************************************************************
232 * RtlUpcaseUnicodeString [NTDLL.520]
234 DWORD WINAPI RtlUpcaseUnicodeString(PUNICODE_STRING dest,PUNICODE_STRING src,BOOLEAN doalloc)
241 dest->MaximumLength = len;
242 dest->Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len);
244 return STATUS_NO_MEMORY;
247 if (dest->MaximumLength < len)
248 return STATUS_BUFFER_OVERFLOW;
249 s=dest->Buffer;t=src->Buffer;
250 /* len is in bytes */
251 for (i=0;i<len/2;i++)
252 s[i] = towupper(t[i]);
253 return STATUS_SUCCESS;
256 /**************************************************************************
257 * RtlxOemStringToUnicodeSize [NTDLL.549]
259 UINT WINAPI RtlxOemStringToUnicodeSize(PSTRING str)
261 return str->Length*2+2;
264 /**************************************************************************
265 * RtlxAnsiStringToUnicodeSize [NTDLL.548]
267 UINT WINAPI RtlxAnsiStringToUnicodeSize(PANSI_STRING str)
269 return str->Length*2+2;
272 /**************************************************************************
273 * RtlIsTextUnicode [NTDLL.417]
275 * Apply various feeble heuristics to guess whether
276 * the text buffer contains Unicode.
277 * FIXME: should implement more tests.
279 DWORD WINAPI RtlIsTextUnicode(LPVOID buf, DWORD len, DWORD *pf)
282 DWORD flags = -1, out_flags = 0;
289 * Apply various tests to the text string. According to the
290 * docs, each test "passed" sets the corresponding flag in
291 * the output flags. But some of the tests are mutually
292 * exclusive, so I don't see how you could pass all tests ...
295 /* Check for an odd length ... pass if even. */
297 out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
299 /* Check for the special unicode marker byte. */
301 out_flags |= IS_TEXT_UNICODE_SIGNATURE;
304 * Check whether the string passed all of the tests.
306 flags &= ITU_IMPLEMENTED_TESTS;
307 if ((out_flags & flags) != flags)
316 /******************************************************************************
317 * RtlCompareUnicodeString [NTDLL]
319 NTSTATUS WINAPI RtlCompareUnicodeString(
320 PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
322 FIXME("(%s,%s,0x%08x),stub!\n",debugstr_w(String1->Buffer),debugstr_w(String1->Buffer),CaseInSensitive);