usp10/tests: A spelling fix in an ok() message.
[wine.git] / dlls / ntdll / rtlstr.c
blob6b60d36a1c4c9911ec42c516b2e60734e4ef3eae
1 /*
2 * Rtl string functions
4 * Copyright (C) 1996-1998 Marcus Meissner
5 * Copyright (C) 2000 Alexandre Julliard
6 * Copyright (C) 2003 Thomas Mertes
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winnt.h"
34 #include "winternl.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37 #include "ntdll_misc.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
41 #define GUID_STRING_LENGTH 38
43 UINT NlsAnsiCodePage = 0;
44 BYTE NlsMbCodePageTag = 0;
45 BYTE NlsMbOemCodePageTag = 0;
47 extern const union cptable cptable_20127; /* 7-bit ASCII */
49 static const union cptable *ansi_table = &cptable_20127;
50 static const union cptable *oem_table = &cptable_20127;
51 static const union cptable* unix_table; /* NULL if UTF8 */
54 /**************************************************************************
55 * __wine_init_codepages (NTDLL.@)
57 * Set the code page once kernel32 is loaded. Should be done differently.
59 void CDECL __wine_init_codepages( const union cptable *ansi, const union cptable *oem,
60 const union cptable *ucp)
62 ansi_table = ansi;
63 oem_table = oem;
64 unix_table = ucp;
65 NlsAnsiCodePage = ansi->info.codepage;
68 int ntdll_umbstowcs(DWORD flags, const char* src, int srclen, WCHAR* dst, int dstlen)
70 #ifdef __APPLE__
71 /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
72 if (!unix_table) flags |= MB_COMPOSITE;
73 #endif
74 return (unix_table) ?
75 wine_cp_mbstowcs( unix_table, flags, src, srclen, dst, dstlen ) :
76 wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
79 int ntdll_wcstoumbs(DWORD flags, const WCHAR* src, int srclen, char* dst, int dstlen,
80 const char* defchar, int *used )
82 if (unix_table)
83 return wine_cp_wcstombs( unix_table, flags, src, srclen, dst, dstlen, defchar, used );
84 if (used) *used = 0; /* all chars are valid for UTF-8 */
85 return wine_utf8_wcstombs( flags, src, srclen, dst, dstlen );
88 /**************************************************************************
89 * RtlInitAnsiString (NTDLL.@)
91 * Initializes a buffered ansi string.
93 * RETURNS
94 * Nothing.
96 * NOTES
97 * Assigns source to target->Buffer. The length of source is assigned to
98 * target->Length and target->MaximumLength. If source is NULL the length
99 * of source is assumed to be 0.
101 void WINAPI RtlInitAnsiString(
102 PANSI_STRING target, /* [I/O] Buffered ansi string to be initialized */
103 PCSZ source) /* [I] '\0' terminated string used to initialize target */
105 if ((target->Buffer = (PCHAR) source))
107 target->Length = strlen(source);
108 target->MaximumLength = target->Length + 1;
110 else target->Length = target->MaximumLength = 0;
113 /**************************************************************************
114 * RtlInitAnsiStringEx (NTDLL.@)
116 * Initializes a buffered ansi string.
118 * RETURNS
119 * An appropriate NTSTATUS value.
121 * NOTES
122 * Assigns source to target->Buffer. The length of source is assigned to
123 * target->Length and target->MaximumLength. If source is NULL the length
124 * of source is assumed to be 0.
126 NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING target, PCSZ source)
128 if (source)
130 unsigned int len = strlen(source);
131 if (len+1 > 0xffff)
132 return STATUS_NAME_TOO_LONG;
134 target->Buffer = (PCHAR) source;
135 target->Length = len;
136 target->MaximumLength = len + 1;
138 else
140 target->Buffer = NULL;
141 target->Length = 0;
142 target->MaximumLength = 0;
144 return STATUS_SUCCESS;
147 /**************************************************************************
148 * RtlInitString (NTDLL.@)
150 * Initializes a buffered string.
152 * RETURNS
153 * Nothing.
155 * NOTES
156 * Assigns source to target->Buffer. The length of source is assigned to
157 * target->Length and target->MaximumLength. If source is NULL the length
158 * of source is assumed to be 0.
160 void WINAPI RtlInitString(
161 PSTRING target, /* [I/O] Buffered string to be initialized */
162 PCSZ source) /* [I] '\0' terminated string used to initialize target */
164 RtlInitAnsiString( target, source );
168 /**************************************************************************
169 * RtlFreeAnsiString (NTDLL.@)
171 void WINAPI RtlFreeAnsiString( PSTRING str )
173 if (str->Buffer)
175 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
176 RtlZeroMemory( str, sizeof(*str) );
181 /**************************************************************************
182 * RtlFreeOemString (NTDLL.@)
184 void WINAPI RtlFreeOemString( PSTRING str )
186 RtlFreeAnsiString( str );
190 /**************************************************************************
191 * RtlCopyString (NTDLL.@)
193 void WINAPI RtlCopyString( STRING *dst, const STRING *src )
195 if (src)
197 unsigned int len = min( src->Length, dst->MaximumLength );
198 memcpy( dst->Buffer, src->Buffer, len );
199 dst->Length = len;
201 else dst->Length = 0;
205 /**************************************************************************
206 * RtlInitUnicodeString (NTDLL.@)
208 * Initializes a buffered unicode string.
210 * RETURNS
211 * Nothing.
213 * NOTES
214 * Assigns source to target->Buffer. The length of source is assigned to
215 * target->Length and target->MaximumLength. If source is NULL the length
216 * of source is assumed to be 0.
218 void WINAPI RtlInitUnicodeString(
219 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
220 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
222 if ((target->Buffer = (PWSTR) source))
224 unsigned int length = strlenW(source) * sizeof(WCHAR);
225 if (length > 0xfffc)
226 length = 0xfffc;
227 target->Length = length;
228 target->MaximumLength = target->Length + sizeof(WCHAR);
230 else target->Length = target->MaximumLength = 0;
234 /**************************************************************************
235 * RtlInitUnicodeStringEx (NTDLL.@)
237 * Initializes a buffered unicode string.
239 * RETURNS
240 * Success: STATUS_SUCCESS. target is initialized.
241 * Failure: STATUS_NAME_TOO_LONG, if the source string is larger than 65532 bytes.
243 * NOTES
244 * Assigns source to target->Buffer. The length of source is assigned to
245 * target->Length and target->MaximumLength. If source is NULL the length
246 * of source is assumed to be 0.
248 NTSTATUS WINAPI RtlInitUnicodeStringEx(
249 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
250 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
252 if (source != NULL) {
253 unsigned int len = strlenW(source) * sizeof(WCHAR);
255 if (len > 0xFFFC) {
256 return STATUS_NAME_TOO_LONG;
257 } else {
258 target->Length = len;
259 target->MaximumLength = len + sizeof(WCHAR);
260 target->Buffer = (PWSTR) source;
261 } /* if */
262 } else {
263 target->Length = 0;
264 target->MaximumLength = 0;
265 target->Buffer = NULL;
266 } /* if */
267 return STATUS_SUCCESS;
271 /**************************************************************************
272 * RtlCreateUnicodeString (NTDLL.@)
274 * Creates a UNICODE_STRING from a null-terminated Unicode string.
276 * RETURNS
277 * Success: TRUE
278 * Failure: FALSE
280 BOOLEAN WINAPI RtlCreateUnicodeString( PUNICODE_STRING target, LPCWSTR src )
282 int len = (strlenW(src) + 1) * sizeof(WCHAR);
283 if (!(target->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return FALSE;
284 memcpy( target->Buffer, src, len );
285 target->MaximumLength = len;
286 target->Length = len - sizeof(WCHAR);
287 return TRUE;
291 /**************************************************************************
292 * RtlCreateUnicodeStringFromAsciiz (NTDLL.@)
294 * Creates a UNICODE_STRING from a null-terminated Ascii string.
296 * RETURNS
297 * Success: TRUE
298 * Failure: FALSE
300 BOOLEAN WINAPI RtlCreateUnicodeStringFromAsciiz( PUNICODE_STRING target, LPCSTR src )
302 STRING ansi;
303 RtlInitAnsiString( &ansi, src );
304 return !RtlAnsiStringToUnicodeString( target, &ansi, TRUE );
308 /**************************************************************************
309 * RtlFreeUnicodeString (NTDLL.@)
311 * Frees a UNICODE_STRING created with RtlCreateUnicodeString() or
312 * RtlCreateUnicodeStringFromAsciiz().
314 * RETURNS
315 * nothing
317 void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str )
319 if (str->Buffer)
321 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
322 RtlZeroMemory( str, sizeof(*str) );
327 /**************************************************************************
328 * RtlCopyUnicodeString (NTDLL.@)
330 * Copies from one UNICODE_STRING to another.
332 * RETURNS
333 * nothing
335 void WINAPI RtlCopyUnicodeString( UNICODE_STRING *dst, const UNICODE_STRING *src )
337 if (src)
339 unsigned int len = min( src->Length, dst->MaximumLength );
340 memcpy( dst->Buffer, src->Buffer, len );
341 dst->Length = len;
342 /* append terminating '\0' if enough space */
343 if (len < dst->MaximumLength) dst->Buffer[len / sizeof(WCHAR)] = 0;
345 else dst->Length = 0;
349 /**************************************************************************
350 * RtlDuplicateUnicodeString (NTDLL.@)
352 * Duplicates a unicode string.
354 * RETURNS
355 * Success: STATUS_SUCCESS. destination contains the duplicated unicode string.
356 * Failure: STATUS_INVALID_PARAMETER, if one of the parameters is illegal.
357 * STATUS_NO_MEMORY, if the allocation fails.
359 * NOTES
360 * For add_nul there are several possible values:
361 * 0 = destination will not be '\0' terminated,
362 * 1 = destination will be '\0' terminated,
363 * 3 = like 1 but for an empty source string produce '\0' terminated empty
364 * Buffer instead of assigning NULL to the Buffer.
365 * Other add_nul values are invalid.
367 NTSTATUS WINAPI RtlDuplicateUnicodeString(
368 int add_nul, /* [I] flag */
369 const UNICODE_STRING *source, /* [I] Unicode string to be duplicated */
370 UNICODE_STRING *destination) /* [O] destination for the duplicated unicode string */
372 if (source == NULL || destination == NULL ||
373 source->Length > source->MaximumLength ||
374 (source->Length == 0 && source->MaximumLength > 0 && source->Buffer == NULL) ||
375 add_nul == 2 || add_nul >= 4 || add_nul < 0) {
376 return STATUS_INVALID_PARAMETER;
377 } else {
378 if (source->Length == 0 && add_nul != 3) {
379 destination->Length = 0;
380 destination->MaximumLength = 0;
381 destination->Buffer = NULL;
382 } else {
383 unsigned int destination_max_len = source->Length;
385 if (add_nul) {
386 destination_max_len += sizeof(WCHAR);
387 } /* if */
388 destination->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, destination_max_len);
389 if (destination->Buffer == NULL) {
390 return STATUS_NO_MEMORY;
391 } else {
392 memcpy(destination->Buffer, source->Buffer, source->Length);
393 destination->Length = source->Length;
394 destination->MaximumLength = source->Length;
395 /* append terminating '\0' if enough space */
396 if (add_nul) {
397 destination->MaximumLength = destination_max_len;
398 destination->Buffer[destination->Length / sizeof(WCHAR)] = 0;
399 } /* if */
400 } /* if */
401 } /* if */
402 } /* if */
403 return STATUS_SUCCESS;
407 /**************************************************************************
408 * RtlEraseUnicodeString (NTDLL.@)
410 * Overwrites a UNICODE_STRING with zeros.
412 * RETURNS
413 * nothing
415 void WINAPI RtlEraseUnicodeString( UNICODE_STRING *str )
417 if (str->Buffer)
419 memset( str->Buffer, 0, str->MaximumLength );
420 str->Length = 0;
426 COMPARISON FUNCTIONS
430 /******************************************************************************
431 * RtlCompareString (NTDLL.@)
433 LONG WINAPI RtlCompareString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
435 unsigned int len;
436 LONG ret = 0;
437 LPCSTR p1, p2;
439 len = min(s1->Length, s2->Length);
440 p1 = s1->Buffer;
441 p2 = s2->Buffer;
443 if (CaseInsensitive)
445 while (!ret && len--) ret = RtlUpperChar(*p1++) - RtlUpperChar(*p2++);
447 else
449 while (!ret && len--) ret = *p1++ - *p2++;
451 if (!ret) ret = s1->Length - s2->Length;
452 return ret;
456 /******************************************************************************
457 * RtlCompareUnicodeStrings (NTDLL.@)
459 LONG WINAPI RtlCompareUnicodeStrings( const WCHAR *s1, SIZE_T len1, const WCHAR *s2, SIZE_T len2,
460 BOOLEAN case_insensitive )
462 LONG ret = 0;
463 SIZE_T len = min( len1, len2 );
465 if (case_insensitive)
467 while (!ret && len--) ret = toupperW(*s1++) - toupperW(*s2++);
469 else
471 while (!ret && len--) ret = *s1++ - *s2++;
473 if (!ret) ret = len1 - len2;
474 return ret;
478 /******************************************************************************
479 * RtlCompareUnicodeString (NTDLL.@)
481 LONG WINAPI RtlCompareUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
482 BOOLEAN CaseInsensitive )
484 return RtlCompareUnicodeStrings( s1->Buffer, s1->Length / sizeof(WCHAR),
485 s2->Buffer, s2->Length / sizeof(WCHAR), CaseInsensitive );
489 /**************************************************************************
490 * RtlEqualString (NTDLL.@)
492 * Determine if two strings are equal.
494 * PARAMS
495 * s1 [I] Source string
496 * s2 [I] String to compare to s1
497 * CaseInsensitive [I] TRUE = Case insensitive, FALSE = Case sensitive
499 * RETURNS
500 * Non-zero if s1 is equal to s2, 0 otherwise.
502 BOOLEAN WINAPI RtlEqualString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
504 if (s1->Length != s2->Length) return FALSE;
505 return !RtlCompareString( s1, s2, CaseInsensitive );
509 /**************************************************************************
510 * RtlEqualUnicodeString (NTDLL.@)
512 * Unicode version of RtlEqualString.
514 BOOLEAN WINAPI RtlEqualUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
515 BOOLEAN CaseInsensitive )
517 if (s1->Length != s2->Length) return FALSE;
518 return !RtlCompareUnicodeString( s1, s2, CaseInsensitive );
522 /**************************************************************************
523 * RtlPrefixString (NTDLL.@)
525 * Determine if one string is a prefix of another.
527 * PARAMS
528 * s1 [I] Prefix to look for in s2
529 * s2 [I] String that may contain s1 as a prefix
530 * ignore_case [I] TRUE = Case insensitive, FALSE = Case sensitive
532 * RETURNS
533 * TRUE if s2 contains s1 as a prefix, FALSE otherwise.
535 BOOLEAN WINAPI RtlPrefixString( const STRING *s1, const STRING *s2, BOOLEAN ignore_case )
537 unsigned int i;
539 if (s1->Length > s2->Length) return FALSE;
540 if (ignore_case)
542 for (i = 0; i < s1->Length; i++)
543 if (RtlUpperChar(s1->Buffer[i]) != RtlUpperChar(s2->Buffer[i])) return FALSE;
545 else
547 for (i = 0; i < s1->Length; i++)
548 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
550 return TRUE;
554 /**************************************************************************
555 * RtlPrefixUnicodeString (NTDLL.@)
557 * Unicode version of RtlPrefixString.
559 BOOLEAN WINAPI RtlPrefixUnicodeString( const UNICODE_STRING *s1,
560 const UNICODE_STRING *s2,
561 BOOLEAN ignore_case )
563 unsigned int i;
565 if (s1->Length > s2->Length) return FALSE;
566 if (ignore_case)
568 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
569 if (toupperW(s1->Buffer[i]) != toupperW(s2->Buffer[i])) return FALSE;
571 else
573 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
574 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
576 return TRUE;
580 /**************************************************************************
581 * RtlEqualComputerName (NTDLL.@)
583 * Determine if two computer names are the same.
585 * PARAMS
586 * left [I] First computer name
587 * right [I] Second computer name
589 * RETURNS
590 * 0 if the names are equal, non-zero otherwise.
592 * NOTES
593 * The comparison is case insensitive.
595 NTSTATUS WINAPI RtlEqualComputerName(const UNICODE_STRING *left,
596 const UNICODE_STRING *right)
598 NTSTATUS ret;
599 STRING upLeft, upRight;
601 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upLeft, left, TRUE )))
603 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upRight, right, TRUE )))
605 ret = RtlEqualString( &upLeft, &upRight, FALSE );
606 RtlFreeOemString( &upRight );
608 RtlFreeOemString( &upLeft );
610 return ret;
614 /**************************************************************************
615 * RtlEqualDomainName (NTDLL.@)
617 * Determine if two domain names are the same.
619 * PARAMS
620 * left [I] First domain name
621 * right [I] Second domain name
623 * RETURNS
624 * 0 if the names are equal, non-zero otherwise.
626 * NOTES
627 * The comparison is case insensitive.
629 NTSTATUS WINAPI RtlEqualDomainName(const UNICODE_STRING *left,
630 const UNICODE_STRING *right)
632 return RtlEqualComputerName(left, right);
636 /**************************************************************************
637 * RtlAnsiCharToUnicodeChar (NTDLL.@)
639 * Converts the first ansi character to a unicode character.
641 * PARAMS
642 * ansi [I/O] Pointer to the ansi string.
644 * RETURNS
645 * Unicode representation of the first character in the ansi string.
647 * NOTES
648 * Upon successful completion, the char pointer ansi points to is
649 * incremented by the size of the character.
651 WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *ansi)
653 WCHAR str;
654 DWORD charSize = sizeof(CHAR);
656 if (wine_is_dbcs_leadbyte(ansi_table, **ansi))
657 charSize++;
659 RtlMultiByteToUnicodeN(&str, sizeof(WCHAR), NULL, *ansi, charSize);
660 *ansi += charSize;
662 return str;
666 COPY BETWEEN ANSI_STRING or UNICODE_STRING
667 there is no parameter checking, it just crashes
671 /**************************************************************************
672 * RtlAnsiStringToUnicodeString (NTDLL.@)
674 * Converts an ansi string to a unicode string.
676 * RETURNS
677 * Success: STATUS_SUCCESS. uni contains the converted string
678 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
679 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
680 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
682 * NOTES
683 * This function always writes a terminating '\0'.
685 NTSTATUS WINAPI RtlAnsiStringToUnicodeString(
686 PUNICODE_STRING uni, /* [I/O] Destination for the unicode string */
687 PCANSI_STRING ansi, /* [I] Ansi string to be converted */
688 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
690 DWORD total = RtlAnsiStringToUnicodeSize( ansi );
692 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
693 uni->Length = total - sizeof(WCHAR);
694 if (doalloc)
696 uni->MaximumLength = total;
697 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
698 return STATUS_NO_MEMORY;
700 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
702 RtlMultiByteToUnicodeN( uni->Buffer, uni->Length, NULL, ansi->Buffer, ansi->Length );
703 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
704 return STATUS_SUCCESS;
708 /**************************************************************************
709 * RtlOemStringToUnicodeString (NTDLL.@)
711 * Converts an oem string to a unicode string.
713 * RETURNS
714 * Success: STATUS_SUCCESS. uni contains the converted string
715 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
716 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
717 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
719 * NOTES
720 * This function always writes a terminating '\0'.
722 NTSTATUS WINAPI RtlOemStringToUnicodeString(
723 UNICODE_STRING *uni, /* [I/O] Destination for the unicode string */
724 const STRING *oem, /* [I] Oem string to be converted */
725 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
727 DWORD total = RtlOemStringToUnicodeSize( oem );
729 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
730 uni->Length = total - sizeof(WCHAR);
731 if (doalloc)
733 uni->MaximumLength = total;
734 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
735 return STATUS_NO_MEMORY;
737 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
739 RtlOemToUnicodeN( uni->Buffer, uni->Length, NULL, oem->Buffer, oem->Length );
740 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
741 return STATUS_SUCCESS;
745 /**************************************************************************
746 * RtlUnicodeStringToAnsiString (NTDLL.@)
748 * Converts a unicode string to an ansi string.
750 * RETURNS
751 * Success: STATUS_SUCCESS. ansi contains the converted string
752 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
753 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
755 * NOTES
756 * This function always writes a terminating '\0'.
757 * It performs a partial copy if ansi is too small.
759 NTSTATUS WINAPI RtlUnicodeStringToAnsiString(
760 STRING *ansi, /* [I/O] Destination for the ansi string */
761 const UNICODE_STRING *uni, /* [I] Unicode string to be converted */
762 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for ansi, FALSE=Use existing buffer */
764 NTSTATUS ret = STATUS_SUCCESS;
765 DWORD len = RtlUnicodeStringToAnsiSize( uni );
767 ansi->Length = len - 1;
768 if (doalloc)
770 ansi->MaximumLength = len;
771 if (!(ansi->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
772 return STATUS_NO_MEMORY;
774 else if (ansi->MaximumLength < len)
776 if (!ansi->MaximumLength) return STATUS_BUFFER_OVERFLOW;
777 ansi->Length = ansi->MaximumLength - 1;
778 ret = STATUS_BUFFER_OVERFLOW;
781 RtlUnicodeToMultiByteN( ansi->Buffer, ansi->Length, NULL, uni->Buffer, uni->Length );
782 ansi->Buffer[ansi->Length] = 0;
783 return ret;
787 /**************************************************************************
788 * RtlUnicodeStringToOemString (NTDLL.@)
790 * Converts a Rtl Unicode string to an OEM string.
792 * PARAMS
793 * oem [O] Destination for OEM string
794 * uni [I] Source Unicode string
795 * doalloc [I] TRUE=Allocate new buffer for oem,FALSE=Use existing buffer
797 * RETURNS
798 * Success: STATUS_SUCCESS. oem contains the converted string
799 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
800 * STATUS_NO_MEMORY, if doalloc is TRUE and allocation fails.
802 * NOTES
803 * If doalloc is TRUE, the length allocated is uni->Length + 1.
804 * This function always '\0' terminates the string returned.
806 NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
807 const UNICODE_STRING *uni,
808 BOOLEAN doalloc )
810 NTSTATUS ret = STATUS_SUCCESS;
811 DWORD len = RtlUnicodeStringToOemSize( uni );
813 oem->Length = len - 1;
814 if (doalloc)
816 oem->MaximumLength = len;
817 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
818 return STATUS_NO_MEMORY;
820 else if (oem->MaximumLength < len)
822 if (!oem->MaximumLength) return STATUS_BUFFER_OVERFLOW;
823 oem->Length = oem->MaximumLength - 1;
824 ret = STATUS_BUFFER_OVERFLOW;
827 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, uni->Buffer, uni->Length );
828 oem->Buffer[oem->Length] = 0;
829 return ret;
833 /**************************************************************************
834 * RtlMultiByteToUnicodeN (NTDLL.@)
836 * Converts a multi-byte string to a Unicode string.
838 * RETURNS
839 * NTSTATUS code
841 * NOTES
842 * Performs a partial copy if dst is too small.
844 NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
845 LPCSTR src, DWORD srclen )
848 int ret = wine_cp_mbstowcs( ansi_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
849 if (reslen)
850 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
851 return STATUS_SUCCESS;
855 /**************************************************************************
856 * RtlOemToUnicodeN (NTDLL.@)
858 * Converts a multi-byte string in the OEM code page to a Unicode string.
860 * RETURNS
861 * NTSTATUS code
863 NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
864 LPCSTR src, DWORD srclen )
866 int ret = wine_cp_mbstowcs( oem_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
867 if (reslen)
868 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
869 return STATUS_SUCCESS;
873 /**************************************************************************
874 * RtlUnicodeToMultiByteN (NTDLL.@)
876 * Converts a Unicode string to a multi-byte string in the ANSI code page.
878 * RETURNS
879 * NTSTATUS code
881 NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
882 LPCWSTR src, DWORD srclen )
884 int ret = wine_cp_wcstombs( ansi_table, 0, src, srclen / sizeof(WCHAR),
885 dst, dstlen, NULL, NULL );
886 if (reslen)
887 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
888 return STATUS_SUCCESS;
892 /**************************************************************************
893 * RtlUnicodeToOemN (NTDLL.@)
895 * Converts a Unicode string to a multi-byte string in the OEM code page.
897 * RETURNS
898 * NTSTATUS code
900 NTSTATUS WINAPI RtlUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
901 LPCWSTR src, DWORD srclen )
903 int ret = wine_cp_wcstombs( oem_table, 0, src, srclen / sizeof(WCHAR),
904 dst, dstlen, NULL, NULL );
905 if (reslen)
906 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
907 return STATUS_SUCCESS;
912 CASE CONVERSIONS
916 /**************************************************************************
917 * RtlUpperChar (NTDLL.@)
919 * Converts an Ascii character to uppercase.
921 * PARAMS
922 * ch [I] Character to convert
924 * RETURNS
925 * The uppercase character value.
927 * NOTES
928 * For the input characters from 'a' .. 'z' it returns 'A' .. 'Z'.
929 * All other input characters are returned unchanged. The locale and
930 * multibyte characters are not taken into account (as native DLL).
932 CHAR WINAPI RtlUpperChar( CHAR ch )
934 if (ch >= 'a' && ch <= 'z') {
935 return ch - 'a' + 'A';
936 } else {
937 return ch;
938 } /* if */
942 /**************************************************************************
943 * RtlUpperString (NTDLL.@)
945 * Converts an Ascii string to uppercase.
947 * PARAMS
948 * dst [O] Destination for converted string
949 * src [I] Source string to convert
951 * RETURNS
952 * Nothing.
954 * NOTES
955 * For the src characters from 'a' .. 'z' it assigns 'A' .. 'Z' to dst.
956 * All other src characters are copied unchanged to dst. The locale and
957 * multibyte characters are not taken into account (as native DLL).
958 * The number of character copied is the minimum of src->Length and
959 * the dst->MaximumLength.
961 void WINAPI RtlUpperString( STRING *dst, const STRING *src )
963 unsigned int i, len = min(src->Length, dst->MaximumLength);
965 for (i = 0; i < len; i++) dst->Buffer[i] = RtlUpperChar(src->Buffer[i]);
966 dst->Length = len;
970 /**************************************************************************
971 * RtlUpcaseUnicodeChar (NTDLL.@)
973 * Converts a Unicode character to uppercase.
975 * PARAMS
976 * wch [I] Character to convert
978 * RETURNS
979 * The uppercase character value.
981 WCHAR WINAPI RtlUpcaseUnicodeChar( WCHAR wch )
983 return toupperW(wch);
987 /**************************************************************************
988 * RtlDowncaseUnicodeChar (NTDLL.@)
990 * Converts a Unicode character to lowercase.
992 * PARAMS
993 * wch [I] Character to convert
995 * RETURNS
996 * The lowercase character value.
998 WCHAR WINAPI RtlDowncaseUnicodeChar(WCHAR wch)
1000 return tolowerW(wch);
1004 /**************************************************************************
1005 * RtlUpcaseUnicodeString (NTDLL.@)
1007 * Converts a Unicode string to uppercase.
1009 * PARAMS
1010 * dest [O] Destination for converted string
1011 * src [I] Source string to convert
1012 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1014 * RETURNS
1015 * Success: STATUS_SUCCESS. dest contains the converted string.
1016 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1017 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1019 * NOTES
1020 * dest is never '\0' terminated because it may be equal to src, and src
1021 * might not be '\0' terminated. dest->Length is only set upon success.
1023 NTSTATUS WINAPI RtlUpcaseUnicodeString( UNICODE_STRING *dest,
1024 const UNICODE_STRING *src,
1025 BOOLEAN doalloc)
1027 DWORD i, len = src->Length;
1029 if (doalloc)
1031 dest->MaximumLength = len;
1032 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1033 return STATUS_NO_MEMORY;
1035 else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
1037 for (i = 0; i < len/sizeof(WCHAR); i++) dest->Buffer[i] = toupperW(src->Buffer[i]);
1038 dest->Length = len;
1039 return STATUS_SUCCESS;
1043 /**************************************************************************
1044 * RtlDowncaseUnicodeString (NTDLL.@)
1046 * Converts a Unicode string to lowercase.
1048 * PARAMS
1049 * dest [O] Destination for converted string
1050 * src [I] Source string to convert
1051 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1053 * RETURNS
1054 * Success: STATUS_SUCCESS. dest contains the converted string.
1055 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1056 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1058 * NOTES
1059 * dest is never '\0' terminated because it may be equal to src, and src
1060 * might not be '\0' terminated. dest->Length is only set upon success.
1062 NTSTATUS WINAPI RtlDowncaseUnicodeString(
1063 UNICODE_STRING *dest,
1064 const UNICODE_STRING *src,
1065 BOOLEAN doalloc)
1067 DWORD i;
1068 DWORD len = src->Length;
1070 if (doalloc) {
1071 dest->MaximumLength = len;
1072 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) {
1073 return STATUS_NO_MEMORY;
1074 } /* if */
1075 } else if (len > dest->MaximumLength) {
1076 return STATUS_BUFFER_OVERFLOW;
1077 } /* if */
1079 for (i = 0; i < len/sizeof(WCHAR); i++) {
1080 dest->Buffer[i] = tolowerW(src->Buffer[i]);
1081 } /* for */
1082 dest->Length = len;
1083 return STATUS_SUCCESS;
1087 /**************************************************************************
1088 * RtlUpcaseUnicodeStringToAnsiString (NTDLL.@)
1090 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1092 * RETURNS
1093 * NTSTATUS code
1095 * NOTES
1096 * writes terminating 0
1098 NTSTATUS WINAPI RtlUpcaseUnicodeStringToAnsiString( STRING *dst,
1099 const UNICODE_STRING *src,
1100 BOOLEAN doalloc )
1102 NTSTATUS ret;
1103 UNICODE_STRING upcase;
1105 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1107 ret = RtlUnicodeStringToAnsiString( dst, &upcase, doalloc );
1108 RtlFreeUnicodeString( &upcase );
1110 return ret;
1114 /**************************************************************************
1115 * RtlUpcaseUnicodeStringToOemString (NTDLL.@)
1117 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1118 * stored in STRING format.
1120 * RETURNS
1121 * NTSTATUS code
1123 * NOTES
1124 * writes terminating 0
1126 NTSTATUS WINAPI RtlUpcaseUnicodeStringToOemString( STRING *dst,
1127 const UNICODE_STRING *src,
1128 BOOLEAN doalloc )
1130 NTSTATUS ret;
1131 UNICODE_STRING upcase;
1133 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1135 ret = RtlUnicodeStringToOemString( dst, &upcase, doalloc );
1136 RtlFreeUnicodeString( &upcase );
1138 return ret;
1142 /**************************************************************************
1143 * RtlUpcaseUnicodeStringToCountedOemString (NTDLL.@)
1145 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1146 * stored in STRING format.
1148 * RETURNS
1149 * NTSTATUS code
1151 * NOTES
1152 * Same as RtlUpcaseUnicodeStringToOemString but doesn't write terminating null
1154 NTSTATUS WINAPI RtlUpcaseUnicodeStringToCountedOemString( STRING *oem,
1155 const UNICODE_STRING *uni,
1156 BOOLEAN doalloc )
1158 NTSTATUS ret;
1159 UNICODE_STRING upcase;
1160 WCHAR tmp[32];
1162 upcase.Buffer = tmp;
1163 upcase.MaximumLength = sizeof(tmp);
1164 ret = RtlUpcaseUnicodeString( &upcase, uni, FALSE );
1165 if (ret == STATUS_BUFFER_OVERFLOW) ret = RtlUpcaseUnicodeString( &upcase, uni, TRUE );
1167 if (!ret)
1169 DWORD len = RtlUnicodeStringToOemSize( &upcase ) - 1;
1170 oem->Length = len;
1171 if (doalloc)
1173 oem->MaximumLength = len;
1174 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1176 ret = STATUS_NO_MEMORY;
1177 goto done;
1180 else if (oem->MaximumLength < len)
1182 ret = STATUS_BUFFER_OVERFLOW;
1183 oem->Length = oem->MaximumLength;
1184 if (!oem->MaximumLength) goto done;
1186 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, upcase.Buffer, upcase.Length );
1187 done:
1188 if (upcase.Buffer != tmp) RtlFreeUnicodeString( &upcase );
1190 return ret;
1194 /**************************************************************************
1195 * RtlUpcaseUnicodeToMultiByteN (NTDLL.@)
1197 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1199 * RETURNS
1200 * NTSTATUS code
1202 NTSTATUS WINAPI RtlUpcaseUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1203 LPCWSTR src, DWORD srclen )
1205 NTSTATUS ret;
1206 LPWSTR upcase;
1207 DWORD i;
1209 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1210 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1211 ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen );
1212 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1213 return ret;
1217 /**************************************************************************
1218 * RtlUpcaseUnicodeToOemN (NTDLL.@)
1220 * Converts a Unicode string to the equivalent OEM upper-case representation.
1222 * RETURNS
1223 * NTSTATUS code
1225 NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1226 LPCWSTR src, DWORD srclen )
1228 NTSTATUS ret;
1229 LPWSTR upcase;
1230 DWORD i;
1232 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1233 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1234 ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen );
1235 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1236 return ret;
1241 STRING SIZE
1245 /**************************************************************************
1246 * RtlOemStringToUnicodeSize (NTDLL.@)
1247 * RtlxOemStringToUnicodeSize (NTDLL.@)
1249 * Calculate the size in bytes necessary for the Unicode conversion of str,
1250 * including the terminating '\0'.
1252 * PARAMS
1253 * str [I] String to calculate the size of
1255 * RETURNS
1256 * The calculated size.
1258 UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str )
1260 int ret = wine_cp_mbstowcs( oem_table, 0, str->Buffer, str->Length, NULL, 0 );
1261 return (ret + 1) * sizeof(WCHAR);
1265 /**************************************************************************
1266 * RtlAnsiStringToUnicodeSize (NTDLL.@)
1267 * RtlxAnsiStringToUnicodeSize (NTDLL.@)
1269 * Calculate the size in bytes necessary for the Unicode conversion of str,
1270 * including the terminating '\0'.
1272 * PARAMS
1273 * str [I] String to calculate the size of
1275 * RETURNS
1276 * The calculated size.
1278 DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str )
1280 DWORD ret;
1281 RtlMultiByteToUnicodeSize( &ret, str->Buffer, str->Length );
1282 return ret + sizeof(WCHAR);
1286 /**************************************************************************
1287 * RtlMultiByteToUnicodeSize (NTDLL.@)
1289 * Compute the size in bytes necessary for the Unicode conversion of str,
1290 * without the terminating '\0'.
1292 * PARAMS
1293 * size [O] Destination for size
1294 * str [I] String to calculate the size of
1295 * len [I] Length of str
1297 * RETURNS
1298 * STATUS_SUCCESS.
1300 NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
1302 *size = wine_cp_mbstowcs( ansi_table, 0, str, len, NULL, 0 ) * sizeof(WCHAR);
1303 return STATUS_SUCCESS;
1307 /**************************************************************************
1308 * RtlUnicodeToMultiByteSize (NTDLL.@)
1310 * Calculate the size in bytes necessary for the multibyte conversion of str,
1311 * without the terminating '\0'.
1313 * PARAMS
1314 * size [O] Destination for size
1315 * str [I] String to calculate the size of
1316 * len [I] Length of str
1318 * RETURNS
1319 * STATUS_SUCCESS.
1321 NTSTATUS WINAPI RtlUnicodeToMultiByteSize( PULONG size, LPCWSTR str, ULONG len )
1323 *size = wine_cp_wcstombs( ansi_table, 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL );
1324 return STATUS_SUCCESS;
1328 /**************************************************************************
1329 * RtlUnicodeStringToAnsiSize (NTDLL.@)
1330 * RtlxUnicodeStringToAnsiSize (NTDLL.@)
1332 * Calculate the size in bytes necessary for the Ansi conversion of str,
1333 * including the terminating '\0'.
1335 * PARAMS
1336 * str [I] String to calculate the size of
1338 * RETURNS
1339 * The calculated size.
1341 DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
1343 DWORD ret;
1344 RtlUnicodeToMultiByteSize( &ret, str->Buffer, str->Length );
1345 return ret + 1;
1349 /**************************************************************************
1350 * RtlUnicodeStringToOemSize (NTDLL.@)
1351 * RtlxUnicodeStringToOemSize (NTDLL.@)
1353 * Calculate the size in bytes necessary for the OEM conversion of str,
1354 * including the terminating '\0'.
1356 * PARAMS
1357 * str [I] String to calculate the size of
1359 * RETURNS
1360 * The calculated size.
1362 DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str )
1364 return wine_cp_wcstombs( oem_table, 0, str->Buffer, str->Length / sizeof(WCHAR),
1365 NULL, 0, NULL, NULL ) + 1;
1369 /**************************************************************************
1370 * RtlAppendAsciizToString (NTDLL.@)
1372 * Concatenates a buffered character string and a '\0' terminated character
1373 * string
1375 * RETURNS
1376 * Success: STATUS_SUCCESS. src is appended to dest.
1377 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1378 * to hold the concatenated string.
1380 * NOTES
1381 * if src is NULL dest is unchanged.
1382 * dest is never '\0' terminated.
1384 NTSTATUS WINAPI RtlAppendAsciizToString(
1385 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1386 LPCSTR src) /* [I] '\0' terminated character string to be concatenated */
1388 if (src != NULL) {
1389 unsigned int src_len = strlen(src);
1390 unsigned int dest_len = src_len + dest->Length;
1392 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1393 memcpy(dest->Buffer + dest->Length, src, src_len);
1394 dest->Length = dest_len;
1395 } /* if */
1396 return STATUS_SUCCESS;
1400 /**************************************************************************
1401 * RtlAppendStringToString (NTDLL.@)
1403 * Concatenates two buffered character strings
1405 * RETURNS
1406 * Success: STATUS_SUCCESS. src is appended to dest.
1407 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1408 * to hold the concatenated string.
1410 * NOTES
1411 * if src->length is zero dest is unchanged.
1412 * dest is never '\0' terminated.
1414 NTSTATUS WINAPI RtlAppendStringToString(
1415 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1416 const STRING *src) /* [I] Buffered character string to be concatenated */
1418 if (src->Length != 0) {
1419 unsigned int dest_len = src->Length + dest->Length;
1421 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1422 memcpy(dest->Buffer + dest->Length, src->Buffer, src->Length);
1423 dest->Length = dest_len;
1424 } /* if */
1425 return STATUS_SUCCESS;
1429 /**************************************************************************
1430 * RtlAppendUnicodeToString (NTDLL.@)
1432 * Concatenates a buffered unicode string and a '\0' terminated unicode
1433 * string
1435 * RETURNS
1436 * Success: STATUS_SUCCESS. src is appended to dest.
1437 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1438 * to hold the concatenated string.
1440 * NOTES
1441 * if src is NULL dest is unchanged.
1442 * dest is '\0' terminated when the MaximumLength allows it.
1443 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1445 * DIFFERENCES
1446 * Does not write in the src->Buffer beyond MaximumLength when
1447 * MaximumLength is odd as the native function does.
1449 NTSTATUS WINAPI RtlAppendUnicodeToString(
1450 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1451 LPCWSTR src) /* [I] '\0' terminated unicode string to be concatenated */
1453 if (src != NULL) {
1454 unsigned int src_len = strlenW(src) * sizeof(WCHAR);
1455 unsigned int dest_len = src_len + dest->Length;
1457 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1458 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src, src_len);
1459 dest->Length = dest_len;
1460 /* append terminating '\0' if enough space */
1461 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1462 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1463 } /* if */
1464 } /* if */
1465 return STATUS_SUCCESS;
1469 /**************************************************************************
1470 * RtlAppendUnicodeStringToString (NTDLL.@)
1472 * Concatenates two buffered unicode strings
1474 * RETURNS
1475 * Success: STATUS_SUCCESS. src is appended to dest.
1476 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1477 * to hold the concatenated string.
1479 * NOTES
1480 * if src->length is zero dest is unchanged.
1481 * dest is '\0' terminated when the MaximumLength allows it.
1482 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1484 * DIFFERENCES
1485 * Does not write in the src->Buffer beyond MaximumLength when
1486 * MaximumLength is odd as the native function does.
1488 NTSTATUS WINAPI RtlAppendUnicodeStringToString(
1489 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1490 const UNICODE_STRING *src) /* [I] Buffered unicode string to be concatenated */
1492 if (src->Length != 0) {
1493 unsigned int dest_len = src->Length + dest->Length;
1495 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1496 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src->Buffer, src->Length);
1497 dest->Length = dest_len;
1498 /* append terminating '\0' if enough space */
1499 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1500 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1501 } /* if */
1502 } /* if */
1503 return STATUS_SUCCESS;
1507 /**************************************************************************
1508 * RtlFindCharInUnicodeString (NTDLL.@)
1510 * Searches for one of several unicode characters in a unicode string.
1512 * RETURNS
1513 * Success: STATUS_SUCCESS. pos contains the position after the character found.
1514 * Failure: STATUS_NOT_FOUND, if none of the search_chars are in main_str.
1516 NTSTATUS WINAPI RtlFindCharInUnicodeString(
1517 int flags, /* [I] Flags */
1518 const UNICODE_STRING *main_str, /* [I] Unicode string in which one or more characters are searched */
1519 const UNICODE_STRING *search_chars, /* [I] Unicode string which contains the characters to search for */
1520 USHORT *pos) /* [O] Position of the first character found + 2 */
1522 unsigned int main_idx, search_idx;
1524 switch (flags) {
1525 case 0:
1526 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1527 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1528 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1529 *pos = (main_idx + 1) * sizeof(WCHAR);
1530 return STATUS_SUCCESS;
1534 *pos = 0;
1535 return STATUS_NOT_FOUND;
1536 case 1:
1537 main_idx = main_str->Length / sizeof(WCHAR);
1538 while (main_idx-- > 0) {
1539 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1540 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1541 *pos = main_idx * sizeof(WCHAR);
1542 return STATUS_SUCCESS;
1546 *pos = 0;
1547 return STATUS_NOT_FOUND;
1548 case 2:
1549 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1550 search_idx = 0;
1551 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1552 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1553 search_idx++;
1555 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1556 *pos = (main_idx + 1) * sizeof(WCHAR);
1557 return STATUS_SUCCESS;
1560 *pos = 0;
1561 return STATUS_NOT_FOUND;
1562 case 3:
1563 main_idx = main_str->Length / sizeof(WCHAR);
1564 while (main_idx-- > 0) {
1565 search_idx = 0;
1566 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1567 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1568 search_idx++;
1570 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1571 *pos = main_idx * sizeof(WCHAR);
1572 return STATUS_SUCCESS;
1575 *pos = 0;
1576 return STATUS_NOT_FOUND;
1577 } /* switch */
1578 return STATUS_NOT_FOUND;
1583 MISC
1586 /**************************************************************************
1587 * RtlIsTextUnicode (NTDLL.@)
1589 * Attempt to guess whether a text buffer is Unicode.
1591 * PARAMS
1592 * buf [I] Text buffer to test
1593 * len [I] Length of buf
1594 * pf [O] Destination for test results
1596 * RETURNS
1597 * TRUE if the buffer is likely Unicode, FALSE otherwise.
1599 * FIXME
1600 * Should implement more tests.
1602 BOOLEAN WINAPI RtlIsTextUnicode( LPCVOID buf, INT len, INT *pf )
1604 static const WCHAR std_control_chars[] = {'\r','\n','\t',' ',0x3000,0};
1605 static const WCHAR byterev_control_chars[] = {0x0d00,0x0a00,0x0900,0x2000,0};
1606 const WCHAR *s = buf;
1607 int i;
1608 unsigned int flags = ~0U, out_flags = 0;
1610 if (len < sizeof(WCHAR))
1612 /* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
1613 if (pf) *pf = 0;
1614 return FALSE;
1616 if (pf)
1617 flags = *pf;
1619 * Apply various tests to the text string. According to the
1620 * docs, each test "passed" sets the corresponding flag in
1621 * the output flags. But some of the tests are mutually
1622 * exclusive, so I don't see how you could pass all tests ...
1625 /* Check for an odd length ... pass if even. */
1626 if (len & 1) out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
1628 if (((const char *)buf)[len - 1] == 0)
1629 len--; /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES */
1631 len /= sizeof(WCHAR);
1632 /* Windows only checks the first 256 characters */
1633 if (len > 256) len = 256;
1635 /* Check for the special byte order unicode marks. */
1636 if (*s == 0xFEFF) out_flags |= IS_TEXT_UNICODE_SIGNATURE;
1637 if (*s == 0xFFFE) out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
1639 /* apply some statistical analysis */
1640 if (flags & IS_TEXT_UNICODE_STATISTICS)
1642 int stats = 0;
1643 /* FIXME: checks only for ASCII characters in the unicode stream */
1644 for (i = 0; i < len; i++)
1646 if (s[i] <= 255) stats++;
1648 if (stats > len / 2)
1649 out_flags |= IS_TEXT_UNICODE_STATISTICS;
1652 /* Check for unicode NULL chars */
1653 if (flags & IS_TEXT_UNICODE_NULL_BYTES)
1655 for (i = 0; i < len; i++)
1657 if (!(s[i] & 0xff) || !(s[i] >> 8))
1659 out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
1660 break;
1665 if (flags & IS_TEXT_UNICODE_CONTROLS)
1667 for (i = 0; i < len; i++)
1669 if (strchrW(std_control_chars, s[i]))
1671 out_flags |= IS_TEXT_UNICODE_CONTROLS;
1672 break;
1677 if (flags & IS_TEXT_UNICODE_REVERSE_CONTROLS)
1679 for (i = 0; i < len; i++)
1681 if (strchrW(byterev_control_chars, s[i]))
1683 out_flags |= IS_TEXT_UNICODE_REVERSE_CONTROLS;
1684 break;
1689 if (pf)
1691 out_flags &= *pf;
1692 *pf = out_flags;
1694 /* check for flags that indicate it's definitely not valid Unicode */
1695 if (out_flags & (IS_TEXT_UNICODE_REVERSE_MASK | IS_TEXT_UNICODE_NOT_UNICODE_MASK)) return FALSE;
1696 /* now check for invalid ASCII, and assume Unicode if so */
1697 if (out_flags & IS_TEXT_UNICODE_NOT_ASCII_MASK) return TRUE;
1698 /* now check for Unicode flags */
1699 if (out_flags & IS_TEXT_UNICODE_UNICODE_MASK) return TRUE;
1700 /* no flags set */
1701 return FALSE;
1705 /**************************************************************************
1706 * RtlCharToInteger (NTDLL.@)
1708 * Converts a character string into its integer equivalent.
1710 * RETURNS
1711 * Success: STATUS_SUCCESS. value contains the converted number
1712 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1713 * STATUS_ACCESS_VIOLATION, if value is NULL.
1715 * NOTES
1716 * For base 0 it uses 10 as base and the string should be in the format
1717 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1718 * For other bases the string should be in the format
1719 * "{whitespace} [+|-] {digits}".
1720 * No check is made for value overflow, only the lower 32 bits are assigned.
1721 * If str is NULL it crashes, as the native function does.
1723 * DIFFERENCES
1724 * This function does not read garbage behind '\0' as the native version does.
1726 NTSTATUS WINAPI RtlCharToInteger(
1727 PCSZ str, /* [I] '\0' terminated single-byte string containing a number */
1728 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1729 ULONG *value) /* [O] Destination for the converted value */
1731 CHAR chCurrent;
1732 int digit;
1733 ULONG RunningTotal = 0;
1734 BOOL bMinus = FALSE;
1736 while (*str != '\0' && *str <= ' ') {
1737 str++;
1738 } /* while */
1740 if (*str == '+') {
1741 str++;
1742 } else if (*str == '-') {
1743 bMinus = TRUE;
1744 str++;
1745 } /* if */
1747 if (base == 0) {
1748 base = 10;
1749 if (str[0] == '0') {
1750 if (str[1] == 'b') {
1751 str += 2;
1752 base = 2;
1753 } else if (str[1] == 'o') {
1754 str += 2;
1755 base = 8;
1756 } else if (str[1] == 'x') {
1757 str += 2;
1758 base = 16;
1759 } /* if */
1760 } /* if */
1761 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1762 return STATUS_INVALID_PARAMETER;
1763 } /* if */
1765 if (value == NULL) {
1766 return STATUS_ACCESS_VIOLATION;
1767 } /* if */
1769 while (*str != '\0') {
1770 chCurrent = *str;
1771 if (chCurrent >= '0' && chCurrent <= '9') {
1772 digit = chCurrent - '0';
1773 } else if (chCurrent >= 'A' && chCurrent <= 'Z') {
1774 digit = chCurrent - 'A' + 10;
1775 } else if (chCurrent >= 'a' && chCurrent <= 'z') {
1776 digit = chCurrent - 'a' + 10;
1777 } else {
1778 digit = -1;
1779 } /* if */
1780 if (digit < 0 || digit >= base) {
1781 *value = bMinus ? -RunningTotal : RunningTotal;
1782 return STATUS_SUCCESS;
1783 } /* if */
1785 RunningTotal = RunningTotal * base + digit;
1786 str++;
1787 } /* while */
1789 *value = bMinus ? -RunningTotal : RunningTotal;
1790 return STATUS_SUCCESS;
1794 /**************************************************************************
1795 * RtlIntegerToChar (NTDLL.@)
1797 * Converts an unsigned integer to a character string.
1799 * RETURNS
1800 * Success: STATUS_SUCCESS. str contains the converted number
1801 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1802 * STATUS_BUFFER_OVERFLOW, if str would be larger than length.
1803 * STATUS_ACCESS_VIOLATION, if str is NULL.
1805 * NOTES
1806 * Instead of base 0 it uses 10 as base.
1807 * Writes at most length characters to the string str.
1808 * Str is '\0' terminated when length allows it.
1809 * When str fits exactly in length characters the '\0' is omitted.
1811 NTSTATUS WINAPI RtlIntegerToChar(
1812 ULONG value, /* [I] Value to be converted */
1813 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1814 ULONG length, /* [I] Length of the str buffer in bytes */
1815 PCHAR str) /* [O] Destination for the converted value */
1817 CHAR buffer[33];
1818 PCHAR pos;
1819 CHAR digit;
1820 ULONG len;
1822 if (base == 0) {
1823 base = 10;
1824 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1825 return STATUS_INVALID_PARAMETER;
1826 } /* if */
1828 pos = &buffer[32];
1829 *pos = '\0';
1831 do {
1832 pos--;
1833 digit = value % base;
1834 value = value / base;
1835 if (digit < 10) {
1836 *pos = '0' + digit;
1837 } else {
1838 *pos = 'A' + digit - 10;
1839 } /* if */
1840 } while (value != 0L);
1842 len = &buffer[32] - pos;
1843 if (len > length) {
1844 return STATUS_BUFFER_OVERFLOW;
1845 } else if (str == NULL) {
1846 return STATUS_ACCESS_VIOLATION;
1847 } else if (len == length) {
1848 memcpy(str, pos, len);
1849 } else {
1850 memcpy(str, pos, len + 1);
1851 } /* if */
1852 return STATUS_SUCCESS;
1856 /**************************************************************************
1857 * RtlUnicodeStringToInteger (NTDLL.@)
1859 * Converts a unicode string into its integer equivalent.
1861 * RETURNS
1862 * Success: STATUS_SUCCESS. value contains the converted number
1863 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1864 * STATUS_ACCESS_VIOLATION, if value is NULL.
1866 * NOTES
1867 * For base 0 it uses 10 as base and the string should be in the format
1868 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1869 * For other bases the string should be in the format
1870 * "{whitespace} [+|-] {digits}".
1871 * No check is made for value overflow, only the lower 32 bits are assigned.
1872 * If str is NULL it crashes, as the native function does.
1874 * DIFFERENCES
1875 * This function does not read garbage on string length 0 as the native
1876 * version does.
1878 NTSTATUS WINAPI RtlUnicodeStringToInteger(
1879 const UNICODE_STRING *str, /* [I] Unicode string to be converted */
1880 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1881 ULONG *value) /* [O] Destination for the converted value */
1883 LPWSTR lpwstr = str->Buffer;
1884 USHORT CharsRemaining = str->Length / sizeof(WCHAR);
1885 WCHAR wchCurrent;
1886 int digit;
1887 ULONG RunningTotal = 0;
1888 BOOL bMinus = FALSE;
1890 while (CharsRemaining >= 1 && *lpwstr <= ' ') {
1891 lpwstr++;
1892 CharsRemaining--;
1893 } /* while */
1895 if (CharsRemaining >= 1) {
1896 if (*lpwstr == '+') {
1897 lpwstr++;
1898 CharsRemaining--;
1899 } else if (*lpwstr == '-') {
1900 bMinus = TRUE;
1901 lpwstr++;
1902 CharsRemaining--;
1903 } /* if */
1904 } /* if */
1906 if (base == 0) {
1907 base = 10;
1908 if (CharsRemaining >= 2 && lpwstr[0] == '0') {
1909 if (lpwstr[1] == 'b') {
1910 lpwstr += 2;
1911 CharsRemaining -= 2;
1912 base = 2;
1913 } else if (lpwstr[1] == 'o') {
1914 lpwstr += 2;
1915 CharsRemaining -= 2;
1916 base = 8;
1917 } else if (lpwstr[1] == 'x') {
1918 lpwstr += 2;
1919 CharsRemaining -= 2;
1920 base = 16;
1921 } /* if */
1922 } /* if */
1923 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1924 return STATUS_INVALID_PARAMETER;
1925 } /* if */
1927 if (value == NULL) {
1928 return STATUS_ACCESS_VIOLATION;
1929 } /* if */
1931 while (CharsRemaining >= 1) {
1932 wchCurrent = *lpwstr;
1933 if (wchCurrent >= '0' && wchCurrent <= '9') {
1934 digit = wchCurrent - '0';
1935 } else if (wchCurrent >= 'A' && wchCurrent <= 'Z') {
1936 digit = wchCurrent - 'A' + 10;
1937 } else if (wchCurrent >= 'a' && wchCurrent <= 'z') {
1938 digit = wchCurrent - 'a' + 10;
1939 } else {
1940 digit = -1;
1941 } /* if */
1942 if (digit < 0 || digit >= base) {
1943 *value = bMinus ? -RunningTotal : RunningTotal;
1944 return STATUS_SUCCESS;
1945 } /* if */
1947 RunningTotal = RunningTotal * base + digit;
1948 lpwstr++;
1949 CharsRemaining--;
1950 } /* while */
1952 *value = bMinus ? -RunningTotal : RunningTotal;
1953 return STATUS_SUCCESS;
1957 /**************************************************************************
1958 * RtlIntegerToUnicodeString (NTDLL.@)
1960 * Converts an unsigned integer to a '\0' terminated unicode string.
1962 * RETURNS
1963 * Success: STATUS_SUCCESS. str contains the converted number
1964 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1965 * STATUS_BUFFER_OVERFLOW, if str is too small to hold the string
1966 * (with the '\0' termination). In this case str->Length
1967 * is set to the length, the string would have (which can
1968 * be larger than the MaximumLength).
1970 * NOTES
1971 * Instead of base 0 it uses 10 as base.
1972 * If str is NULL it crashes, as the native function does.
1974 * DIFFERENCES
1975 * Do not return STATUS_BUFFER_OVERFLOW when the string is long enough.
1976 * The native function does this when the string would be longer than 16
1977 * characters even when the string parameter is long enough.
1979 NTSTATUS WINAPI RtlIntegerToUnicodeString(
1980 ULONG value, /* [I] Value to be converted */
1981 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1982 UNICODE_STRING *str) /* [O] Destination for the converted value */
1984 WCHAR buffer[33];
1985 PWCHAR pos;
1986 WCHAR digit;
1988 if (base == 0) {
1989 base = 10;
1990 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1991 return STATUS_INVALID_PARAMETER;
1992 } /* if */
1994 pos = &buffer[32];
1995 *pos = '\0';
1997 do {
1998 pos--;
1999 digit = value % base;
2000 value = value / base;
2001 if (digit < 10) {
2002 *pos = '0' + digit;
2003 } else {
2004 *pos = 'A' + digit - 10;
2005 } /* if */
2006 } while (value != 0L);
2008 str->Length = (&buffer[32] - pos) * sizeof(WCHAR);
2009 if (str->Length >= str->MaximumLength) {
2010 return STATUS_BUFFER_OVERFLOW;
2011 } else {
2012 memcpy(str->Buffer, pos, str->Length + sizeof(WCHAR));
2013 } /* if */
2014 return STATUS_SUCCESS;
2018 /*************************************************************************
2019 * RtlGUIDFromString (NTDLL.@)
2021 * Convert a string representation of a GUID into a GUID.
2023 * PARAMS
2024 * str [I] String representation in the format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
2025 * guid [O] Destination for the converted GUID
2027 * RETURNS
2028 * Success: STATUS_SUCCESS. guid contains the converted value.
2029 * Failure: STATUS_INVALID_PARAMETER, if str is not in the expected format.
2031 * SEE ALSO
2032 * See RtlStringFromGUID.
2034 NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING str, GUID* guid)
2036 int i = 0;
2037 const WCHAR *lpszCLSID = str->Buffer;
2038 BYTE* lpOut = (BYTE*)guid;
2040 TRACE("(%s,%p)\n", debugstr_us(str), guid);
2042 /* Convert string: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
2043 * to memory: DWORD... WORD WORD BYTES............
2045 while (i <= 37)
2047 switch (i)
2049 case 0:
2050 if (*lpszCLSID != '{')
2051 return STATUS_INVALID_PARAMETER;
2052 break;
2054 case 9: case 14: case 19: case 24:
2055 if (*lpszCLSID != '-')
2056 return STATUS_INVALID_PARAMETER;
2057 break;
2059 case 37:
2060 if (*lpszCLSID != '}')
2061 return STATUS_INVALID_PARAMETER;
2062 break;
2064 default:
2066 WCHAR ch = *lpszCLSID, ch2 = lpszCLSID[1];
2067 unsigned char byte;
2069 /* Read two hex digits as a byte value */
2070 if (ch >= '0' && ch <= '9') ch = ch - '0';
2071 else if (ch >= 'a' && ch <= 'f') ch = ch - 'a' + 10;
2072 else if (ch >= 'A' && ch <= 'F') ch = ch - 'A' + 10;
2073 else return STATUS_INVALID_PARAMETER;
2075 if (ch2 >= '0' && ch2 <= '9') ch2 = ch2 - '0';
2076 else if (ch2 >= 'a' && ch2 <= 'f') ch2 = ch2 - 'a' + 10;
2077 else if (ch2 >= 'A' && ch2 <= 'F') ch2 = ch2 - 'A' + 10;
2078 else return STATUS_INVALID_PARAMETER;
2080 byte = ch << 4 | ch2;
2082 switch (i)
2084 #ifndef WORDS_BIGENDIAN
2085 /* For Big Endian machines, we store the data such that the
2086 * dword/word members can be read as DWORDS and WORDS correctly. */
2087 /* Dword */
2088 case 1: lpOut[3] = byte; break;
2089 case 3: lpOut[2] = byte; break;
2090 case 5: lpOut[1] = byte; break;
2091 case 7: lpOut[0] = byte; lpOut += 4; break;
2092 /* Word */
2093 case 10: case 15: lpOut[1] = byte; break;
2094 case 12: case 17: lpOut[0] = byte; lpOut += 2; break;
2095 #endif
2096 /* Byte */
2097 default: lpOut[0] = byte; lpOut++; break;
2099 lpszCLSID++; /* Skip 2nd character of byte */
2100 i++;
2103 lpszCLSID++;
2104 i++;
2107 return STATUS_SUCCESS;
2110 /*************************************************************************
2111 * RtlStringFromGUID (NTDLL.@)
2113 * Convert a GUID into a string representation of a GUID.
2115 * PARAMS
2116 * guid [I] GUID to convert
2117 * str [O] Destination for the converted string
2119 * RETURNS
2120 * Success: STATUS_SUCCESS. str contains the converted value.
2121 * Failure: STATUS_NO_MEMORY, if memory for str cannot be allocated.
2123 * SEE ALSO
2124 * See RtlGUIDFromString.
2126 NTSTATUS WINAPI RtlStringFromGUID(const GUID* guid, UNICODE_STRING *str)
2128 static const WCHAR szFormat[] = { '{','%','0','8','l','X','-',
2129 '%','0','4','X','-', '%','0','4','X','-','%','0','2','X','%','0','2','X',
2130 '-', '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
2131 '%','0','2','X','%','0','2','X','}','\0' };
2133 TRACE("(%p,%p)\n", guid, str);
2135 str->Length = GUID_STRING_LENGTH * sizeof(WCHAR);
2136 str->MaximumLength = str->Length + sizeof(WCHAR);
2137 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, str->MaximumLength);
2138 if (!str->Buffer)
2140 str->Length = str->MaximumLength = 0;
2141 return STATUS_NO_MEMORY;
2143 sprintfW(str->Buffer, szFormat, guid->Data1, guid->Data2, guid->Data3,
2144 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
2145 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
2147 return STATUS_SUCCESS;
2150 /******************************************************************************
2151 * RtlHashUnicodeString [NTDLL.@]
2153 NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING string, BOOLEAN case_insensitive, ULONG alg, ULONG *hash)
2155 unsigned int i;
2157 if (!string || !hash) return STATUS_INVALID_PARAMETER;
2159 switch (alg)
2161 case HASH_STRING_ALGORITHM_DEFAULT:
2162 case HASH_STRING_ALGORITHM_X65599:
2163 break;
2164 default:
2165 return STATUS_INVALID_PARAMETER;
2168 *hash = 0;
2169 for (i = 0; i < string->Length/sizeof(WCHAR); i++)
2170 *hash = *hash*65599 + (case_insensitive ? toupperW(string->Buffer[i]) : string->Buffer[i]);
2172 return STATUS_SUCCESS;