ntdll: Implement ProcessPriorityClass in NtQueryInformationProcess.
[wine.git] / dlls / ntdll / rtlstr.c
blob190bc0176be305aaaf1ecf24f66e2767f64d15c2
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 static const union cptable *ansi_table;
48 static const union cptable *oem_table;
49 static const union cptable* unix_table; /* NULL if UTF8 */
52 /**************************************************************************
53 * __wine_init_codepages (NTDLL.@)
55 * Set the code page once kernel32 is loaded. Should be done differently.
57 void CDECL __wine_init_codepages( const union cptable *ansi, const union cptable *oem,
58 const union cptable *ucp)
60 ansi_table = ansi;
61 oem_table = oem;
62 unix_table = ucp;
63 NlsAnsiCodePage = ansi->info.codepage;
64 init_directories();
67 int ntdll_umbstowcs(DWORD flags, const char* src, int srclen, WCHAR* dst, int dstlen)
69 #ifdef __APPLE__
70 /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
71 if (!unix_table) flags |= MB_COMPOSITE;
72 #endif
73 return (unix_table) ?
74 wine_cp_mbstowcs( unix_table, flags, src, srclen, dst, dstlen ) :
75 wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
78 int ntdll_wcstoumbs(DWORD flags, const WCHAR* src, int srclen, char* dst, int dstlen,
79 const char* defchar, int *used )
81 if (unix_table)
82 return wine_cp_wcstombs( unix_table, flags, src, srclen, dst, dstlen, defchar, used );
83 if (used) *used = 0; /* all chars are valid for UTF-8 */
84 return wine_utf8_wcstombs( flags, src, srclen, dst, dstlen );
87 /**************************************************************************
88 * RtlInitAnsiString (NTDLL.@)
90 * Initializes a buffered ansi string.
92 * RETURNS
93 * Nothing.
95 * NOTES
96 * Assigns source to target->Buffer. The length of source is assigned to
97 * target->Length and target->MaximumLength. If source is NULL the length
98 * of source is assumed to be 0.
100 void WINAPI RtlInitAnsiString(
101 PANSI_STRING target, /* [I/O] Buffered ansi string to be initialized */
102 PCSZ source) /* [I] '\0' terminated string used to initialize target */
104 if ((target->Buffer = (PCHAR) source))
106 target->Length = strlen(source);
107 target->MaximumLength = target->Length + 1;
109 else target->Length = target->MaximumLength = 0;
112 /**************************************************************************
113 * RtlInitAnsiStringEx (NTDLL.@)
115 * Initializes a buffered ansi string.
117 * RETURNS
118 * An appropriate NTSTATUS value.
120 * NOTES
121 * Assigns source to target->Buffer. The length of source is assigned to
122 * target->Length and target->MaximumLength. If source is NULL the length
123 * of source is assumed to be 0.
125 NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING target, PCSZ source)
127 if (source)
129 unsigned int len = strlen(source);
130 if (len+1 > 0xffff)
131 return STATUS_NAME_TOO_LONG;
133 target->Buffer = (PCHAR) source;
134 target->Length = len;
135 target->MaximumLength = len + 1;
137 else
139 target->Buffer = NULL;
140 target->Length = 0;
141 target->MaximumLength = 0;
143 return STATUS_SUCCESS;
146 /**************************************************************************
147 * RtlInitString (NTDLL.@)
149 * Initializes a buffered string.
151 * RETURNS
152 * Nothing.
154 * NOTES
155 * Assigns source to target->Buffer. The length of source is assigned to
156 * target->Length and target->MaximumLength. If source is NULL the length
157 * of source is assumed to be 0.
159 void WINAPI RtlInitString(
160 PSTRING target, /* [I/O] Buffered string to be initialized */
161 PCSZ source) /* [I] '\0' terminated string used to initialize target */
163 RtlInitAnsiString( target, source );
167 /**************************************************************************
168 * RtlFreeAnsiString (NTDLL.@)
170 void WINAPI RtlFreeAnsiString( PSTRING str )
172 if (str->Buffer)
174 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
175 RtlZeroMemory( str, sizeof(*str) );
180 /**************************************************************************
181 * RtlFreeOemString (NTDLL.@)
183 void WINAPI RtlFreeOemString( PSTRING str )
185 RtlFreeAnsiString( str );
189 /**************************************************************************
190 * RtlCopyString (NTDLL.@)
192 void WINAPI RtlCopyString( STRING *dst, const STRING *src )
194 if (src)
196 unsigned int len = min( src->Length, dst->MaximumLength );
197 memcpy( dst->Buffer, src->Buffer, len );
198 dst->Length = len;
200 else dst->Length = 0;
204 /**************************************************************************
205 * RtlInitUnicodeString (NTDLL.@)
207 * Initializes a buffered unicode string.
209 * RETURNS
210 * Nothing.
212 * NOTES
213 * Assigns source to target->Buffer. The length of source is assigned to
214 * target->Length and target->MaximumLength. If source is NULL the length
215 * of source is assumed to be 0.
217 void WINAPI RtlInitUnicodeString(
218 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
219 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
221 if ((target->Buffer = (PWSTR) source))
223 unsigned int length = strlenW(source) * sizeof(WCHAR);
224 if (length > 0xfffc)
225 length = 0xfffc;
226 target->Length = length;
227 target->MaximumLength = target->Length + sizeof(WCHAR);
229 else target->Length = target->MaximumLength = 0;
233 /**************************************************************************
234 * RtlInitUnicodeStringEx (NTDLL.@)
236 * Initializes a buffered unicode string.
238 * RETURNS
239 * Success: STATUS_SUCCESS. target is initialized.
240 * Failure: STATUS_NAME_TOO_LONG, if the source string is larger than 65532 bytes.
242 * NOTES
243 * Assigns source to target->Buffer. The length of source is assigned to
244 * target->Length and target->MaximumLength. If source is NULL the length
245 * of source is assumed to be 0.
247 NTSTATUS WINAPI RtlInitUnicodeStringEx(
248 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
249 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
251 if (source != NULL) {
252 unsigned int len = strlenW(source) * sizeof(WCHAR);
254 if (len > 0xFFFC) {
255 return STATUS_NAME_TOO_LONG;
256 } else {
257 target->Length = len;
258 target->MaximumLength = len + sizeof(WCHAR);
259 target->Buffer = (PWSTR) source;
260 } /* if */
261 } else {
262 target->Length = 0;
263 target->MaximumLength = 0;
264 target->Buffer = NULL;
265 } /* if */
266 return STATUS_SUCCESS;
270 /**************************************************************************
271 * RtlCreateUnicodeString (NTDLL.@)
273 * Creates a UNICODE_STRING from a null-terminated Unicode string.
275 * RETURNS
276 * Success: TRUE
277 * Failure: FALSE
279 BOOLEAN WINAPI RtlCreateUnicodeString( PUNICODE_STRING target, LPCWSTR src )
281 int len = (strlenW(src) + 1) * sizeof(WCHAR);
282 if (!(target->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return FALSE;
283 memcpy( target->Buffer, src, len );
284 target->MaximumLength = len;
285 target->Length = len - sizeof(WCHAR);
286 return TRUE;
290 /**************************************************************************
291 * RtlCreateUnicodeStringFromAsciiz (NTDLL.@)
293 * Creates a UNICODE_STRING from a null-terminated Ascii string.
295 * RETURNS
296 * Success: TRUE
297 * Failure: FALSE
299 BOOLEAN WINAPI RtlCreateUnicodeStringFromAsciiz( PUNICODE_STRING target, LPCSTR src )
301 STRING ansi;
302 RtlInitAnsiString( &ansi, src );
303 return !RtlAnsiStringToUnicodeString( target, &ansi, TRUE );
307 /**************************************************************************
308 * RtlFreeUnicodeString (NTDLL.@)
310 * Frees a UNICODE_STRING created with RtlCreateUnicodeString() or
311 * RtlCreateUnicodeStringFromAsciiz().
313 * RETURNS
314 * nothing
316 void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str )
318 if (str->Buffer)
320 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
321 RtlZeroMemory( str, sizeof(*str) );
326 /**************************************************************************
327 * RtlCopyUnicodeString (NTDLL.@)
329 * Copies from one UNICODE_STRING to another.
331 * RETURNS
332 * nothing
334 void WINAPI RtlCopyUnicodeString( UNICODE_STRING *dst, const UNICODE_STRING *src )
336 if (src)
338 unsigned int len = min( src->Length, dst->MaximumLength );
339 memcpy( dst->Buffer, src->Buffer, len );
340 dst->Length = len;
341 /* append terminating '\0' if enough space */
342 if (len < dst->MaximumLength) dst->Buffer[len / sizeof(WCHAR)] = 0;
344 else dst->Length = 0;
348 /**************************************************************************
349 * RtlDuplicateUnicodeString (NTDLL.@)
351 * Duplicates a unicode string.
353 * RETURNS
354 * Success: STATUS_SUCCESS. destination contains the duplicated unicode string.
355 * Failure: STATUS_INVALID_PARAMETER, if one of the parameters is illegal.
356 * STATUS_NO_MEMORY, if the allocation fails.
358 * NOTES
359 * For add_nul there are several possible values:
360 * 0 = destination will not be '\0' terminated,
361 * 1 = destination will be '\0' terminated,
362 * 3 = like 1 but for an empty source string produce '\0' terminated empty
363 * Buffer instead of assigning NULL to the Buffer.
364 * Other add_nul values are invalid.
366 NTSTATUS WINAPI RtlDuplicateUnicodeString(
367 int add_nul, /* [I] flag */
368 const UNICODE_STRING *source, /* [I] Unicode string to be duplicated */
369 UNICODE_STRING *destination) /* [O] destination for the duplicated unicode string */
371 if (source == NULL || destination == NULL ||
372 source->Length > source->MaximumLength ||
373 (source->Length == 0 && source->MaximumLength > 0 && source->Buffer == NULL) ||
374 add_nul == 2 || add_nul >= 4 || add_nul < 0) {
375 return STATUS_INVALID_PARAMETER;
376 } else {
377 if (source->Length == 0 && add_nul != 3) {
378 destination->Length = 0;
379 destination->MaximumLength = 0;
380 destination->Buffer = NULL;
381 } else {
382 unsigned int destination_max_len = source->Length;
384 if (add_nul) {
385 destination_max_len += sizeof(WCHAR);
386 } /* if */
387 destination->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, destination_max_len);
388 if (destination->Buffer == NULL) {
389 return STATUS_NO_MEMORY;
390 } else {
391 memcpy(destination->Buffer, source->Buffer, source->Length);
392 destination->Length = source->Length;
393 destination->MaximumLength = source->Length;
394 /* append terminating '\0' if enough space */
395 if (add_nul) {
396 destination->MaximumLength = destination_max_len;
397 destination->Buffer[destination->Length / sizeof(WCHAR)] = 0;
398 } /* if */
399 } /* if */
400 } /* if */
401 } /* if */
402 return STATUS_SUCCESS;
406 /**************************************************************************
407 * RtlEraseUnicodeString (NTDLL.@)
409 * Overwrites a UNICODE_STRING with zeros.
411 * RETURNS
412 * nothing
414 void WINAPI RtlEraseUnicodeString( UNICODE_STRING *str )
416 if (str->Buffer)
418 memset( str->Buffer, 0, str->MaximumLength );
419 str->Length = 0;
425 COMPARISON FUNCTIONS
429 /******************************************************************************
430 * RtlCompareString (NTDLL.@)
432 LONG WINAPI RtlCompareString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
434 unsigned int len;
435 LONG ret = 0;
436 LPCSTR p1, p2;
438 len = min(s1->Length, s2->Length);
439 p1 = s1->Buffer;
440 p2 = s2->Buffer;
442 if (CaseInsensitive)
444 while (!ret && len--) ret = RtlUpperChar(*p1++) - RtlUpperChar(*p2++);
446 else
448 while (!ret && len--) ret = *p1++ - *p2++;
450 if (!ret) ret = s1->Length - s2->Length;
451 return ret;
455 /******************************************************************************
456 * RtlCompareUnicodeStrings (NTDLL.@)
458 LONG WINAPI RtlCompareUnicodeStrings( const WCHAR *s1, SIZE_T len1, const WCHAR *s2, SIZE_T len2,
459 BOOLEAN case_insensitive )
461 LONG ret = 0;
462 SIZE_T len = min( len1, len2 );
464 if (case_insensitive)
466 while (!ret && len--) ret = toupperW(*s1++) - toupperW(*s2++);
468 else
470 while (!ret && len--) ret = *s1++ - *s2++;
472 if (!ret) ret = len1 - len2;
473 return ret;
477 /******************************************************************************
478 * RtlCompareUnicodeString (NTDLL.@)
480 LONG WINAPI RtlCompareUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
481 BOOLEAN CaseInsensitive )
483 return RtlCompareUnicodeStrings( s1->Buffer, s1->Length / sizeof(WCHAR),
484 s2->Buffer, s2->Length / sizeof(WCHAR), CaseInsensitive );
488 /**************************************************************************
489 * RtlEqualString (NTDLL.@)
491 * Determine if two strings are equal.
493 * PARAMS
494 * s1 [I] Source string
495 * s2 [I] String to compare to s1
496 * CaseInsensitive [I] TRUE = Case insensitive, FALSE = Case sensitive
498 * RETURNS
499 * Non-zero if s1 is equal to s2, 0 otherwise.
501 BOOLEAN WINAPI RtlEqualString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
503 if (s1->Length != s2->Length) return FALSE;
504 return !RtlCompareString( s1, s2, CaseInsensitive );
508 /**************************************************************************
509 * RtlEqualUnicodeString (NTDLL.@)
511 * Unicode version of RtlEqualString.
513 BOOLEAN WINAPI RtlEqualUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
514 BOOLEAN CaseInsensitive )
516 if (s1->Length != s2->Length) return FALSE;
517 return !RtlCompareUnicodeString( s1, s2, CaseInsensitive );
521 /**************************************************************************
522 * RtlPrefixString (NTDLL.@)
524 * Determine if one string is a prefix of another.
526 * PARAMS
527 * s1 [I] Prefix to look for in s2
528 * s2 [I] String that may contain s1 as a prefix
529 * ignore_case [I] TRUE = Case insensitive, FALSE = Case sensitive
531 * RETURNS
532 * TRUE if s2 contains s1 as a prefix, FALSE otherwise.
534 BOOLEAN WINAPI RtlPrefixString( const STRING *s1, const STRING *s2, BOOLEAN ignore_case )
536 unsigned int i;
538 if (s1->Length > s2->Length) return FALSE;
539 if (ignore_case)
541 for (i = 0; i < s1->Length; i++)
542 if (RtlUpperChar(s1->Buffer[i]) != RtlUpperChar(s2->Buffer[i])) return FALSE;
544 else
546 for (i = 0; i < s1->Length; i++)
547 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
549 return TRUE;
553 /**************************************************************************
554 * RtlPrefixUnicodeString (NTDLL.@)
556 * Unicode version of RtlPrefixString.
558 BOOLEAN WINAPI RtlPrefixUnicodeString( const UNICODE_STRING *s1,
559 const UNICODE_STRING *s2,
560 BOOLEAN ignore_case )
562 unsigned int i;
564 if (s1->Length > s2->Length) return FALSE;
565 if (ignore_case)
567 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
568 if (toupperW(s1->Buffer[i]) != toupperW(s2->Buffer[i])) return FALSE;
570 else
572 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
573 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
575 return TRUE;
579 /**************************************************************************
580 * RtlEqualComputerName (NTDLL.@)
582 * Determine if two computer names are the same.
584 * PARAMS
585 * left [I] First computer name
586 * right [I] Second computer name
588 * RETURNS
589 * 0 if the names are equal, non-zero otherwise.
591 * NOTES
592 * The comparison is case insensitive.
594 NTSTATUS WINAPI RtlEqualComputerName(const UNICODE_STRING *left,
595 const UNICODE_STRING *right)
597 NTSTATUS ret;
598 STRING upLeft, upRight;
600 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upLeft, left, TRUE )))
602 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upRight, right, TRUE )))
604 ret = RtlEqualString( &upLeft, &upRight, FALSE );
605 RtlFreeOemString( &upRight );
607 RtlFreeOemString( &upLeft );
609 return ret;
613 /**************************************************************************
614 * RtlEqualDomainName (NTDLL.@)
616 * Determine if two domain names are the same.
618 * PARAMS
619 * left [I] First domain name
620 * right [I] Second domain name
622 * RETURNS
623 * 0 if the names are equal, non-zero otherwise.
625 * NOTES
626 * The comparison is case insensitive.
628 NTSTATUS WINAPI RtlEqualDomainName(const UNICODE_STRING *left,
629 const UNICODE_STRING *right)
631 return RtlEqualComputerName(left, right);
635 /**************************************************************************
636 * RtlAnsiCharToUnicodeChar (NTDLL.@)
638 * Converts the first ansi character to a unicode character.
640 * PARAMS
641 * ansi [I/O] Pointer to the ansi string.
643 * RETURNS
644 * Unicode representation of the first character in the ansi string.
646 * NOTES
647 * Upon successful completion, the char pointer ansi points to is
648 * incremented by the size of the character.
650 WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *ansi)
652 WCHAR str;
653 DWORD charSize = sizeof(CHAR);
655 if (wine_is_dbcs_leadbyte(ansi_table, **ansi))
656 charSize++;
658 RtlMultiByteToUnicodeN(&str, sizeof(WCHAR), NULL, *ansi, charSize);
659 *ansi += charSize;
661 return str;
665 COPY BETWEEN ANSI_STRING or UNICODE_STRING
666 there is no parameter checking, it just crashes
670 /**************************************************************************
671 * RtlAnsiStringToUnicodeString (NTDLL.@)
673 * Converts an ansi string to a unicode string.
675 * RETURNS
676 * Success: STATUS_SUCCESS. uni contains the converted string
677 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
678 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
679 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
681 * NOTES
682 * This function always writes a terminating '\0'.
684 NTSTATUS WINAPI RtlAnsiStringToUnicodeString(
685 PUNICODE_STRING uni, /* [I/O] Destination for the unicode string */
686 PCANSI_STRING ansi, /* [I] Ansi string to be converted */
687 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
689 DWORD total = RtlAnsiStringToUnicodeSize( ansi );
691 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
692 uni->Length = total - sizeof(WCHAR);
693 if (doalloc)
695 uni->MaximumLength = total;
696 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
697 return STATUS_NO_MEMORY;
699 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
701 RtlMultiByteToUnicodeN( uni->Buffer, uni->Length, NULL, ansi->Buffer, ansi->Length );
702 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
703 return STATUS_SUCCESS;
707 /**************************************************************************
708 * RtlOemStringToUnicodeString (NTDLL.@)
710 * Converts an oem string to a unicode string.
712 * RETURNS
713 * Success: STATUS_SUCCESS. uni contains the converted string
714 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
715 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
716 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
718 * NOTES
719 * This function always writes a terminating '\0'.
721 NTSTATUS WINAPI RtlOemStringToUnicodeString(
722 UNICODE_STRING *uni, /* [I/O] Destination for the unicode string */
723 const STRING *oem, /* [I] Oem string to be converted */
724 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
726 DWORD total = RtlOemStringToUnicodeSize( oem );
728 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
729 uni->Length = total - sizeof(WCHAR);
730 if (doalloc)
732 uni->MaximumLength = total;
733 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
734 return STATUS_NO_MEMORY;
736 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
738 RtlOemToUnicodeN( uni->Buffer, uni->Length, NULL, oem->Buffer, oem->Length );
739 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
740 return STATUS_SUCCESS;
744 /**************************************************************************
745 * RtlUnicodeStringToAnsiString (NTDLL.@)
747 * Converts a unicode string to an ansi string.
749 * RETURNS
750 * Success: STATUS_SUCCESS. ansi contains the converted string
751 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
752 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
754 * NOTES
755 * This function always writes a terminating '\0'.
756 * It performs a partial copy if ansi is too small.
758 NTSTATUS WINAPI RtlUnicodeStringToAnsiString(
759 STRING *ansi, /* [I/O] Destination for the ansi string */
760 const UNICODE_STRING *uni, /* [I] Unicode string to be converted */
761 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for ansi, FALSE=Use existing buffer */
763 NTSTATUS ret = STATUS_SUCCESS;
764 DWORD len = RtlUnicodeStringToAnsiSize( uni );
766 ansi->Length = len - 1;
767 if (doalloc)
769 ansi->MaximumLength = len;
770 if (!(ansi->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
771 return STATUS_NO_MEMORY;
773 else if (ansi->MaximumLength < len)
775 if (!ansi->MaximumLength) return STATUS_BUFFER_OVERFLOW;
776 ansi->Length = ansi->MaximumLength - 1;
777 ret = STATUS_BUFFER_OVERFLOW;
780 RtlUnicodeToMultiByteN( ansi->Buffer, ansi->Length, NULL, uni->Buffer, uni->Length );
781 ansi->Buffer[ansi->Length] = 0;
782 return ret;
786 /**************************************************************************
787 * RtlUnicodeStringToOemString (NTDLL.@)
789 * Converts a Rtl Unicode string to an OEM string.
791 * PARAMS
792 * oem [O] Destination for OEM string
793 * uni [I] Source Unicode string
794 * doalloc [I] TRUE=Allocate new buffer for oem,FALSE=Use existing buffer
796 * RETURNS
797 * Success: STATUS_SUCCESS. oem contains the converted string
798 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
799 * STATUS_NO_MEMORY, if doalloc is TRUE and allocation fails.
801 * NOTES
802 * If doalloc is TRUE, the length allocated is uni->Length + 1.
803 * This function always '\0' terminates the string returned.
805 NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
806 const UNICODE_STRING *uni,
807 BOOLEAN doalloc )
809 NTSTATUS ret = STATUS_SUCCESS;
810 DWORD len = RtlUnicodeStringToOemSize( uni );
812 oem->Length = len - 1;
813 if (doalloc)
815 oem->MaximumLength = len;
816 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
817 return STATUS_NO_MEMORY;
819 else if (oem->MaximumLength < len)
821 if (!oem->MaximumLength) return STATUS_BUFFER_OVERFLOW;
822 oem->Length = oem->MaximumLength - 1;
823 ret = STATUS_BUFFER_OVERFLOW;
826 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, uni->Buffer, uni->Length );
827 oem->Buffer[oem->Length] = 0;
828 return ret;
832 /**************************************************************************
833 * RtlMultiByteToUnicodeN (NTDLL.@)
835 * Converts a multi-byte string to a Unicode string.
837 * RETURNS
838 * NTSTATUS code
840 * NOTES
841 * Performs a partial copy if dst is too small.
843 NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
844 LPCSTR src, DWORD srclen )
847 int ret = wine_cp_mbstowcs( ansi_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
848 if (reslen)
849 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
850 return STATUS_SUCCESS;
854 /**************************************************************************
855 * RtlOemToUnicodeN (NTDLL.@)
857 * Converts a multi-byte string in the OEM code page to a Unicode string.
859 * RETURNS
860 * NTSTATUS code
862 NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
863 LPCSTR src, DWORD srclen )
865 int ret = wine_cp_mbstowcs( oem_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
866 if (reslen)
867 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
868 return STATUS_SUCCESS;
872 /**************************************************************************
873 * RtlUnicodeToMultiByteN (NTDLL.@)
875 * Converts a Unicode string to a multi-byte string in the ANSI code page.
877 * RETURNS
878 * NTSTATUS code
880 NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
881 LPCWSTR src, DWORD srclen )
883 int ret = wine_cp_wcstombs( ansi_table, 0, src, srclen / sizeof(WCHAR),
884 dst, dstlen, NULL, NULL );
885 if (reslen)
886 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
887 return STATUS_SUCCESS;
891 /**************************************************************************
892 * RtlUnicodeToOemN (NTDLL.@)
894 * Converts a Unicode string to a multi-byte string in the OEM code page.
896 * RETURNS
897 * NTSTATUS code
899 NTSTATUS WINAPI RtlUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
900 LPCWSTR src, DWORD srclen )
902 int ret = wine_cp_wcstombs( oem_table, 0, src, srclen / sizeof(WCHAR),
903 dst, dstlen, NULL, NULL );
904 if (reslen)
905 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
906 return STATUS_SUCCESS;
911 CASE CONVERSIONS
915 /**************************************************************************
916 * RtlUpperChar (NTDLL.@)
918 * Converts an Ascii character to uppercase.
920 * PARAMS
921 * ch [I] Character to convert
923 * RETURNS
924 * The uppercase character value.
926 * NOTES
927 * For the input characters from 'a' .. 'z' it returns 'A' .. 'Z'.
928 * All other input characters are returned unchanged. The locale and
929 * multibyte characters are not taken into account (as native DLL).
931 CHAR WINAPI RtlUpperChar( CHAR ch )
933 if (ch >= 'a' && ch <= 'z') {
934 return ch - 'a' + 'A';
935 } else {
936 return ch;
937 } /* if */
941 /**************************************************************************
942 * RtlUpperString (NTDLL.@)
944 * Converts an Ascii string to uppercase.
946 * PARAMS
947 * dst [O] Destination for converted string
948 * src [I] Source string to convert
950 * RETURNS
951 * Nothing.
953 * NOTES
954 * For the src characters from 'a' .. 'z' it assigns 'A' .. 'Z' to dst.
955 * All other src characters are copied unchanged to dst. The locale and
956 * multibyte characters are not taken into account (as native DLL).
957 * The number of character copied is the minimum of src->Length and
958 * the dst->MaximumLength.
960 void WINAPI RtlUpperString( STRING *dst, const STRING *src )
962 unsigned int i, len = min(src->Length, dst->MaximumLength);
964 for (i = 0; i < len; i++) dst->Buffer[i] = RtlUpperChar(src->Buffer[i]);
965 dst->Length = len;
969 /**************************************************************************
970 * RtlUpcaseUnicodeChar (NTDLL.@)
972 * Converts a Unicode character to uppercase.
974 * PARAMS
975 * wch [I] Character to convert
977 * RETURNS
978 * The uppercase character value.
980 WCHAR WINAPI RtlUpcaseUnicodeChar( WCHAR wch )
982 return toupperW(wch);
986 /**************************************************************************
987 * RtlDowncaseUnicodeChar (NTDLL.@)
989 * Converts a Unicode character to lowercase.
991 * PARAMS
992 * wch [I] Character to convert
994 * RETURNS
995 * The lowercase character value.
997 WCHAR WINAPI RtlDowncaseUnicodeChar(WCHAR wch)
999 return tolowerW(wch);
1003 /**************************************************************************
1004 * RtlUpcaseUnicodeString (NTDLL.@)
1006 * Converts a Unicode string to uppercase.
1008 * PARAMS
1009 * dest [O] Destination for converted string
1010 * src [I] Source string to convert
1011 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1013 * RETURNS
1014 * Success: STATUS_SUCCESS. dest contains the converted string.
1015 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1016 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1018 * NOTES
1019 * dest is never '\0' terminated because it may be equal to src, and src
1020 * might not be '\0' terminated. dest->Length is only set upon success.
1022 NTSTATUS WINAPI RtlUpcaseUnicodeString( UNICODE_STRING *dest,
1023 const UNICODE_STRING *src,
1024 BOOLEAN doalloc)
1026 DWORD i, len = src->Length;
1028 if (doalloc)
1030 dest->MaximumLength = len;
1031 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1032 return STATUS_NO_MEMORY;
1034 else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
1036 for (i = 0; i < len/sizeof(WCHAR); i++) dest->Buffer[i] = toupperW(src->Buffer[i]);
1037 dest->Length = len;
1038 return STATUS_SUCCESS;
1042 /**************************************************************************
1043 * RtlDowncaseUnicodeString (NTDLL.@)
1045 * Converts a Unicode string to lowercase.
1047 * PARAMS
1048 * dest [O] Destination for converted string
1049 * src [I] Source string to convert
1050 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1052 * RETURNS
1053 * Success: STATUS_SUCCESS. dest contains the converted string.
1054 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1055 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1057 * NOTES
1058 * dest is never '\0' terminated because it may be equal to src, and src
1059 * might not be '\0' terminated. dest->Length is only set upon success.
1061 NTSTATUS WINAPI RtlDowncaseUnicodeString(
1062 UNICODE_STRING *dest,
1063 const UNICODE_STRING *src,
1064 BOOLEAN doalloc)
1066 DWORD i;
1067 DWORD len = src->Length;
1069 if (doalloc) {
1070 dest->MaximumLength = len;
1071 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) {
1072 return STATUS_NO_MEMORY;
1073 } /* if */
1074 } else if (len > dest->MaximumLength) {
1075 return STATUS_BUFFER_OVERFLOW;
1076 } /* if */
1078 for (i = 0; i < len/sizeof(WCHAR); i++) {
1079 dest->Buffer[i] = tolowerW(src->Buffer[i]);
1080 } /* for */
1081 dest->Length = len;
1082 return STATUS_SUCCESS;
1086 /**************************************************************************
1087 * RtlUpcaseUnicodeStringToAnsiString (NTDLL.@)
1089 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1091 * RETURNS
1092 * NTSTATUS code
1094 * NOTES
1095 * writes terminating 0
1097 NTSTATUS WINAPI RtlUpcaseUnicodeStringToAnsiString( STRING *dst,
1098 const UNICODE_STRING *src,
1099 BOOLEAN doalloc )
1101 NTSTATUS ret;
1102 UNICODE_STRING upcase;
1104 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1106 ret = RtlUnicodeStringToAnsiString( dst, &upcase, doalloc );
1107 RtlFreeUnicodeString( &upcase );
1109 return ret;
1113 /**************************************************************************
1114 * RtlUpcaseUnicodeStringToOemString (NTDLL.@)
1116 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1117 * stored in STRING format.
1119 * RETURNS
1120 * NTSTATUS code
1122 * NOTES
1123 * writes terminating 0
1125 NTSTATUS WINAPI RtlUpcaseUnicodeStringToOemString( STRING *dst,
1126 const UNICODE_STRING *src,
1127 BOOLEAN doalloc )
1129 NTSTATUS ret;
1130 UNICODE_STRING upcase;
1132 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1134 ret = RtlUnicodeStringToOemString( dst, &upcase, doalloc );
1135 RtlFreeUnicodeString( &upcase );
1137 return ret;
1141 /**************************************************************************
1142 * RtlUpcaseUnicodeStringToCountedOemString (NTDLL.@)
1144 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1145 * stored in STRING format.
1147 * RETURNS
1148 * NTSTATUS code
1150 * NOTES
1151 * Same as RtlUpcaseUnicodeStringToOemString but doesn't write terminating null
1153 NTSTATUS WINAPI RtlUpcaseUnicodeStringToCountedOemString( STRING *oem,
1154 const UNICODE_STRING *uni,
1155 BOOLEAN doalloc )
1157 NTSTATUS ret;
1158 UNICODE_STRING upcase;
1159 WCHAR tmp[32];
1161 upcase.Buffer = tmp;
1162 upcase.MaximumLength = sizeof(tmp);
1163 ret = RtlUpcaseUnicodeString( &upcase, uni, FALSE );
1164 if (ret == STATUS_BUFFER_OVERFLOW) ret = RtlUpcaseUnicodeString( &upcase, uni, TRUE );
1166 if (!ret)
1168 DWORD len = RtlUnicodeStringToOemSize( &upcase ) - 1;
1169 oem->Length = len;
1170 if (doalloc)
1172 oem->MaximumLength = len;
1173 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1175 ret = STATUS_NO_MEMORY;
1176 goto done;
1179 else if (oem->MaximumLength < len)
1181 ret = STATUS_BUFFER_OVERFLOW;
1182 oem->Length = oem->MaximumLength;
1183 if (!oem->MaximumLength) goto done;
1185 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, upcase.Buffer, upcase.Length );
1186 done:
1187 if (upcase.Buffer != tmp) RtlFreeUnicodeString( &upcase );
1189 return ret;
1193 /**************************************************************************
1194 * RtlUpcaseUnicodeToMultiByteN (NTDLL.@)
1196 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1198 * RETURNS
1199 * NTSTATUS code
1201 NTSTATUS WINAPI RtlUpcaseUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1202 LPCWSTR src, DWORD srclen )
1204 NTSTATUS ret;
1205 LPWSTR upcase;
1206 DWORD i;
1208 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1209 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1210 ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen );
1211 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1212 return ret;
1216 /**************************************************************************
1217 * RtlUpcaseUnicodeToOemN (NTDLL.@)
1219 * Converts a Unicode string to the equivalent OEM upper-case representation.
1221 * RETURNS
1222 * NTSTATUS code
1224 NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1225 LPCWSTR src, DWORD srclen )
1227 NTSTATUS ret;
1228 LPWSTR upcase;
1229 DWORD i;
1231 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1232 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1233 ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen );
1234 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1235 return ret;
1240 STRING SIZE
1244 /**************************************************************************
1245 * RtlOemStringToUnicodeSize (NTDLL.@)
1246 * RtlxOemStringToUnicodeSize (NTDLL.@)
1248 * Calculate the size in bytes necessary for the Unicode conversion of str,
1249 * including the terminating '\0'.
1251 * PARAMS
1252 * str [I] String to calculate the size of
1254 * RETURNS
1255 * The calculated size.
1257 UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str )
1259 int ret = wine_cp_mbstowcs( oem_table, 0, str->Buffer, str->Length, NULL, 0 );
1260 return (ret + 1) * sizeof(WCHAR);
1264 /**************************************************************************
1265 * RtlAnsiStringToUnicodeSize (NTDLL.@)
1266 * RtlxAnsiStringToUnicodeSize (NTDLL.@)
1268 * Calculate the size in bytes necessary for the Unicode conversion of str,
1269 * including the terminating '\0'.
1271 * PARAMS
1272 * str [I] String to calculate the size of
1274 * RETURNS
1275 * The calculated size.
1277 DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str )
1279 DWORD ret;
1280 RtlMultiByteToUnicodeSize( &ret, str->Buffer, str->Length );
1281 return ret + sizeof(WCHAR);
1285 /**************************************************************************
1286 * RtlMultiByteToUnicodeSize (NTDLL.@)
1288 * Compute the size in bytes necessary for the Unicode conversion of str,
1289 * without the terminating '\0'.
1291 * PARAMS
1292 * size [O] Destination for size
1293 * str [I] String to calculate the size of
1294 * len [I] Length of str
1296 * RETURNS
1297 * STATUS_SUCCESS.
1299 NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
1301 *size = wine_cp_mbstowcs( ansi_table, 0, str, len, NULL, 0 ) * sizeof(WCHAR);
1302 return STATUS_SUCCESS;
1306 /**************************************************************************
1307 * RtlUnicodeToMultiByteSize (NTDLL.@)
1309 * Calculate the size in bytes necessary for the multibyte conversion of str,
1310 * without the terminating '\0'.
1312 * PARAMS
1313 * size [O] Destination for size
1314 * str [I] String to calculate the size of
1315 * len [I] Length of str
1317 * RETURNS
1318 * STATUS_SUCCESS.
1320 NTSTATUS WINAPI RtlUnicodeToMultiByteSize( PULONG size, LPCWSTR str, ULONG len )
1322 *size = wine_cp_wcstombs( ansi_table, 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL );
1323 return STATUS_SUCCESS;
1327 /**************************************************************************
1328 * RtlUnicodeStringToAnsiSize (NTDLL.@)
1329 * RtlxUnicodeStringToAnsiSize (NTDLL.@)
1331 * Calculate the size in bytes necessary for the Ansi conversion of str,
1332 * including the terminating '\0'.
1334 * PARAMS
1335 * str [I] String to calculate the size of
1337 * RETURNS
1338 * The calculated size.
1340 DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
1342 DWORD ret;
1343 RtlUnicodeToMultiByteSize( &ret, str->Buffer, str->Length );
1344 return ret + 1;
1348 /**************************************************************************
1349 * RtlUnicodeStringToOemSize (NTDLL.@)
1350 * RtlxUnicodeStringToOemSize (NTDLL.@)
1352 * Calculate the size in bytes necessary for the OEM conversion of str,
1353 * including the terminating '\0'.
1355 * PARAMS
1356 * str [I] String to calculate the size of
1358 * RETURNS
1359 * The calculated size.
1361 DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str )
1363 return wine_cp_wcstombs( oem_table, 0, str->Buffer, str->Length / sizeof(WCHAR),
1364 NULL, 0, NULL, NULL ) + 1;
1368 /**************************************************************************
1369 * RtlAppendAsciizToString (NTDLL.@)
1371 * Concatenates a buffered character string and a '\0' terminated character
1372 * string
1374 * RETURNS
1375 * Success: STATUS_SUCCESS. src is appended to dest.
1376 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1377 * to hold the concatenated string.
1379 * NOTES
1380 * if src is NULL dest is unchanged.
1381 * dest is never '\0' terminated.
1383 NTSTATUS WINAPI RtlAppendAsciizToString(
1384 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1385 LPCSTR src) /* [I] '\0' terminated character string to be concatenated */
1387 if (src != NULL) {
1388 unsigned int src_len = strlen(src);
1389 unsigned int dest_len = src_len + dest->Length;
1391 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1392 memcpy(dest->Buffer + dest->Length, src, src_len);
1393 dest->Length = dest_len;
1394 } /* if */
1395 return STATUS_SUCCESS;
1399 /**************************************************************************
1400 * RtlAppendStringToString (NTDLL.@)
1402 * Concatenates two buffered character strings
1404 * RETURNS
1405 * Success: STATUS_SUCCESS. src is appended to dest.
1406 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1407 * to hold the concatenated string.
1409 * NOTES
1410 * if src->length is zero dest is unchanged.
1411 * dest is never '\0' terminated.
1413 NTSTATUS WINAPI RtlAppendStringToString(
1414 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1415 const STRING *src) /* [I] Buffered character string to be concatenated */
1417 if (src->Length != 0) {
1418 unsigned int dest_len = src->Length + dest->Length;
1420 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1421 memcpy(dest->Buffer + dest->Length, src->Buffer, src->Length);
1422 dest->Length = dest_len;
1423 } /* if */
1424 return STATUS_SUCCESS;
1428 /**************************************************************************
1429 * RtlAppendUnicodeToString (NTDLL.@)
1431 * Concatenates a buffered unicode string and a '\0' terminated unicode
1432 * string
1434 * RETURNS
1435 * Success: STATUS_SUCCESS. src is appended to dest.
1436 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1437 * to hold the concatenated string.
1439 * NOTES
1440 * if src is NULL dest is unchanged.
1441 * dest is '\0' terminated when the MaximumLength allows it.
1442 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1444 * DIFFERENCES
1445 * Does not write in the src->Buffer beyond MaximumLength when
1446 * MaximumLength is odd as the native function does.
1448 NTSTATUS WINAPI RtlAppendUnicodeToString(
1449 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1450 LPCWSTR src) /* [I] '\0' terminated unicode string to be concatenated */
1452 if (src != NULL) {
1453 unsigned int src_len = strlenW(src) * sizeof(WCHAR);
1454 unsigned int dest_len = src_len + dest->Length;
1456 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1457 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src, src_len);
1458 dest->Length = dest_len;
1459 /* append terminating '\0' if enough space */
1460 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1461 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1462 } /* if */
1463 } /* if */
1464 return STATUS_SUCCESS;
1468 /**************************************************************************
1469 * RtlAppendUnicodeStringToString (NTDLL.@)
1471 * Concatenates two buffered unicode strings
1473 * RETURNS
1474 * Success: STATUS_SUCCESS. src is appended to dest.
1475 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1476 * to hold the concatenated string.
1478 * NOTES
1479 * if src->length is zero dest is unchanged.
1480 * dest is '\0' terminated when the MaximumLength allows it.
1481 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1483 * DIFFERENCES
1484 * Does not write in the src->Buffer beyond MaximumLength when
1485 * MaximumLength is odd as the native function does.
1487 NTSTATUS WINAPI RtlAppendUnicodeStringToString(
1488 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1489 const UNICODE_STRING *src) /* [I] Buffered unicode string to be concatenated */
1491 if (src->Length != 0) {
1492 unsigned int dest_len = src->Length + dest->Length;
1494 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1495 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src->Buffer, src->Length);
1496 dest->Length = dest_len;
1497 /* append terminating '\0' if enough space */
1498 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1499 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1500 } /* if */
1501 } /* if */
1502 return STATUS_SUCCESS;
1506 /**************************************************************************
1507 * RtlFindCharInUnicodeString (NTDLL.@)
1509 * Searches for one of several unicode characters in a unicode string.
1511 * RETURNS
1512 * Success: STATUS_SUCCESS. pos contains the position after the character found.
1513 * Failure: STATUS_NOT_FOUND, if none of the search_chars are in main_str.
1515 NTSTATUS WINAPI RtlFindCharInUnicodeString(
1516 int flags, /* [I] Flags */
1517 const UNICODE_STRING *main_str, /* [I] Unicode string in which one or more characters are searched */
1518 const UNICODE_STRING *search_chars, /* [I] Unicode string which contains the characters to search for */
1519 USHORT *pos) /* [O] Position of the first character found + 2 */
1521 unsigned int main_idx, search_idx;
1523 switch (flags) {
1524 case 0:
1525 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1526 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1527 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1528 *pos = (main_idx + 1) * sizeof(WCHAR);
1529 return STATUS_SUCCESS;
1533 *pos = 0;
1534 return STATUS_NOT_FOUND;
1535 case 1:
1536 main_idx = main_str->Length / sizeof(WCHAR);
1537 while (main_idx-- > 0) {
1538 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1539 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1540 *pos = main_idx * sizeof(WCHAR);
1541 return STATUS_SUCCESS;
1545 *pos = 0;
1546 return STATUS_NOT_FOUND;
1547 case 2:
1548 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1549 search_idx = 0;
1550 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1551 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1552 search_idx++;
1554 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1555 *pos = (main_idx + 1) * sizeof(WCHAR);
1556 return STATUS_SUCCESS;
1559 *pos = 0;
1560 return STATUS_NOT_FOUND;
1561 case 3:
1562 main_idx = main_str->Length / sizeof(WCHAR);
1563 while (main_idx-- > 0) {
1564 search_idx = 0;
1565 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1566 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1567 search_idx++;
1569 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1570 *pos = main_idx * sizeof(WCHAR);
1571 return STATUS_SUCCESS;
1574 *pos = 0;
1575 return STATUS_NOT_FOUND;
1576 } /* switch */
1577 return STATUS_NOT_FOUND;
1582 MISC
1585 /**************************************************************************
1586 * RtlIsTextUnicode (NTDLL.@)
1588 * Attempt to guess whether a text buffer is Unicode.
1590 * PARAMS
1591 * buf [I] Text buffer to test
1592 * len [I] Length of buf
1593 * pf [O] Destination for test results
1595 * RETURNS
1596 * TRUE if the buffer is likely Unicode, FALSE otherwise.
1598 * FIXME
1599 * Should implement more tests.
1601 BOOLEAN WINAPI RtlIsTextUnicode( LPCVOID buf, INT len, INT *pf )
1603 static const WCHAR std_control_chars[] = {'\r','\n','\t',' ',0x3000,0};
1604 static const WCHAR byterev_control_chars[] = {0x0d00,0x0a00,0x0900,0x2000,0};
1605 const WCHAR *s = buf;
1606 int i;
1607 unsigned int flags = ~0U, out_flags = 0;
1609 if (len < sizeof(WCHAR))
1611 /* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
1612 if (pf) *pf = 0;
1613 return FALSE;
1615 if (pf)
1616 flags = *pf;
1618 * Apply various tests to the text string. According to the
1619 * docs, each test "passed" sets the corresponding flag in
1620 * the output flags. But some of the tests are mutually
1621 * exclusive, so I don't see how you could pass all tests ...
1624 /* Check for an odd length ... pass if even. */
1625 if (len & 1) out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
1627 if (((const char *)buf)[len - 1] == 0)
1628 len--; /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES */
1630 len /= sizeof(WCHAR);
1631 /* Windows only checks the first 256 characters */
1632 if (len > 256) len = 256;
1634 /* Check for the special byte order unicode marks. */
1635 if (*s == 0xFEFF) out_flags |= IS_TEXT_UNICODE_SIGNATURE;
1636 if (*s == 0xFFFE) out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
1638 /* apply some statistical analysis */
1639 if (flags & IS_TEXT_UNICODE_STATISTICS)
1641 int stats = 0;
1642 /* FIXME: checks only for ASCII characters in the unicode stream */
1643 for (i = 0; i < len; i++)
1645 if (s[i] <= 255) stats++;
1647 if (stats > len / 2)
1648 out_flags |= IS_TEXT_UNICODE_STATISTICS;
1651 /* Check for unicode NULL chars */
1652 if (flags & IS_TEXT_UNICODE_NULL_BYTES)
1654 for (i = 0; i < len; i++)
1656 if (!(s[i] & 0xff) || !(s[i] >> 8))
1658 out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
1659 break;
1664 if (flags & IS_TEXT_UNICODE_CONTROLS)
1666 for (i = 0; i < len; i++)
1668 if (strchrW(std_control_chars, s[i]))
1670 out_flags |= IS_TEXT_UNICODE_CONTROLS;
1671 break;
1676 if (flags & IS_TEXT_UNICODE_REVERSE_CONTROLS)
1678 for (i = 0; i < len; i++)
1680 if (strchrW(byterev_control_chars, s[i]))
1682 out_flags |= IS_TEXT_UNICODE_REVERSE_CONTROLS;
1683 break;
1688 if (pf)
1690 out_flags &= *pf;
1691 *pf = out_flags;
1693 /* check for flags that indicate it's definitely not valid Unicode */
1694 if (out_flags & (IS_TEXT_UNICODE_REVERSE_MASK | IS_TEXT_UNICODE_NOT_UNICODE_MASK)) return FALSE;
1695 /* now check for invalid ASCII, and assume Unicode if so */
1696 if (out_flags & IS_TEXT_UNICODE_NOT_ASCII_MASK) return TRUE;
1697 /* now check for Unicode flags */
1698 if (out_flags & IS_TEXT_UNICODE_UNICODE_MASK) return TRUE;
1699 /* no flags set */
1700 return FALSE;
1704 /**************************************************************************
1705 * RtlCharToInteger (NTDLL.@)
1707 * Converts a character string into its integer equivalent.
1709 * RETURNS
1710 * Success: STATUS_SUCCESS. value contains the converted number
1711 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1712 * STATUS_ACCESS_VIOLATION, if value is NULL.
1714 * NOTES
1715 * For base 0 it uses 10 as base and the string should be in the format
1716 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1717 * For other bases the string should be in the format
1718 * "{whitespace} [+|-] {digits}".
1719 * No check is made for value overflow, only the lower 32 bits are assigned.
1720 * If str is NULL it crashes, as the native function does.
1722 * DIFFERENCES
1723 * This function does not read garbage behind '\0' as the native version does.
1725 NTSTATUS WINAPI RtlCharToInteger(
1726 PCSZ str, /* [I] '\0' terminated single-byte string containing a number */
1727 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1728 ULONG *value) /* [O] Destination for the converted value */
1730 CHAR chCurrent;
1731 int digit;
1732 ULONG RunningTotal = 0;
1733 BOOL bMinus = FALSE;
1735 while (*str != '\0' && *str <= ' ') {
1736 str++;
1737 } /* while */
1739 if (*str == '+') {
1740 str++;
1741 } else if (*str == '-') {
1742 bMinus = TRUE;
1743 str++;
1744 } /* if */
1746 if (base == 0) {
1747 base = 10;
1748 if (str[0] == '0') {
1749 if (str[1] == 'b') {
1750 str += 2;
1751 base = 2;
1752 } else if (str[1] == 'o') {
1753 str += 2;
1754 base = 8;
1755 } else if (str[1] == 'x') {
1756 str += 2;
1757 base = 16;
1758 } /* if */
1759 } /* if */
1760 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1761 return STATUS_INVALID_PARAMETER;
1762 } /* if */
1764 if (value == NULL) {
1765 return STATUS_ACCESS_VIOLATION;
1766 } /* if */
1768 while (*str != '\0') {
1769 chCurrent = *str;
1770 if (chCurrent >= '0' && chCurrent <= '9') {
1771 digit = chCurrent - '0';
1772 } else if (chCurrent >= 'A' && chCurrent <= 'Z') {
1773 digit = chCurrent - 'A' + 10;
1774 } else if (chCurrent >= 'a' && chCurrent <= 'z') {
1775 digit = chCurrent - 'a' + 10;
1776 } else {
1777 digit = -1;
1778 } /* if */
1779 if (digit < 0 || digit >= base) {
1780 *value = bMinus ? -RunningTotal : RunningTotal;
1781 return STATUS_SUCCESS;
1782 } /* if */
1784 RunningTotal = RunningTotal * base + digit;
1785 str++;
1786 } /* while */
1788 *value = bMinus ? -RunningTotal : RunningTotal;
1789 return STATUS_SUCCESS;
1793 /**************************************************************************
1794 * RtlIntegerToChar (NTDLL.@)
1796 * Converts an unsigned integer to a character string.
1798 * RETURNS
1799 * Success: STATUS_SUCCESS. str contains the converted number
1800 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1801 * STATUS_BUFFER_OVERFLOW, if str would be larger than length.
1802 * STATUS_ACCESS_VIOLATION, if str is NULL.
1804 * NOTES
1805 * Instead of base 0 it uses 10 as base.
1806 * Writes at most length characters to the string str.
1807 * Str is '\0' terminated when length allows it.
1808 * When str fits exactly in length characters the '\0' is omitted.
1810 NTSTATUS WINAPI RtlIntegerToChar(
1811 ULONG value, /* [I] Value to be converted */
1812 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1813 ULONG length, /* [I] Length of the str buffer in bytes */
1814 PCHAR str) /* [O] Destination for the converted value */
1816 CHAR buffer[33];
1817 PCHAR pos;
1818 CHAR digit;
1819 ULONG len;
1821 if (base == 0) {
1822 base = 10;
1823 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1824 return STATUS_INVALID_PARAMETER;
1825 } /* if */
1827 pos = &buffer[32];
1828 *pos = '\0';
1830 do {
1831 pos--;
1832 digit = value % base;
1833 value = value / base;
1834 if (digit < 10) {
1835 *pos = '0' + digit;
1836 } else {
1837 *pos = 'A' + digit - 10;
1838 } /* if */
1839 } while (value != 0L);
1841 len = &buffer[32] - pos;
1842 if (len > length) {
1843 return STATUS_BUFFER_OVERFLOW;
1844 } else if (str == NULL) {
1845 return STATUS_ACCESS_VIOLATION;
1846 } else if (len == length) {
1847 memcpy(str, pos, len);
1848 } else {
1849 memcpy(str, pos, len + 1);
1850 } /* if */
1851 return STATUS_SUCCESS;
1855 /**************************************************************************
1856 * RtlUnicodeStringToInteger (NTDLL.@)
1858 * Converts a unicode string into its integer equivalent.
1860 * RETURNS
1861 * Success: STATUS_SUCCESS. value contains the converted number
1862 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1863 * STATUS_ACCESS_VIOLATION, if value is NULL.
1865 * NOTES
1866 * For base 0 it uses 10 as base and the string should be in the format
1867 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1868 * For other bases the string should be in the format
1869 * "{whitespace} [+|-] {digits}".
1870 * No check is made for value overflow, only the lower 32 bits are assigned.
1871 * If str is NULL it crashes, as the native function does.
1873 * DIFFERENCES
1874 * This function does not read garbage on string length 0 as the native
1875 * version does.
1877 NTSTATUS WINAPI RtlUnicodeStringToInteger(
1878 const UNICODE_STRING *str, /* [I] Unicode string to be converted */
1879 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1880 ULONG *value) /* [O] Destination for the converted value */
1882 LPWSTR lpwstr = str->Buffer;
1883 USHORT CharsRemaining = str->Length / sizeof(WCHAR);
1884 WCHAR wchCurrent;
1885 int digit;
1886 ULONG RunningTotal = 0;
1887 BOOL bMinus = FALSE;
1889 while (CharsRemaining >= 1 && *lpwstr <= ' ') {
1890 lpwstr++;
1891 CharsRemaining--;
1892 } /* while */
1894 if (CharsRemaining >= 1) {
1895 if (*lpwstr == '+') {
1896 lpwstr++;
1897 CharsRemaining--;
1898 } else if (*lpwstr == '-') {
1899 bMinus = TRUE;
1900 lpwstr++;
1901 CharsRemaining--;
1902 } /* if */
1903 } /* if */
1905 if (base == 0) {
1906 base = 10;
1907 if (CharsRemaining >= 2 && lpwstr[0] == '0') {
1908 if (lpwstr[1] == 'b') {
1909 lpwstr += 2;
1910 CharsRemaining -= 2;
1911 base = 2;
1912 } else if (lpwstr[1] == 'o') {
1913 lpwstr += 2;
1914 CharsRemaining -= 2;
1915 base = 8;
1916 } else if (lpwstr[1] == 'x') {
1917 lpwstr += 2;
1918 CharsRemaining -= 2;
1919 base = 16;
1920 } /* if */
1921 } /* if */
1922 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1923 return STATUS_INVALID_PARAMETER;
1924 } /* if */
1926 if (value == NULL) {
1927 return STATUS_ACCESS_VIOLATION;
1928 } /* if */
1930 while (CharsRemaining >= 1) {
1931 wchCurrent = *lpwstr;
1932 if (wchCurrent >= '0' && wchCurrent <= '9') {
1933 digit = wchCurrent - '0';
1934 } else if (wchCurrent >= 'A' && wchCurrent <= 'Z') {
1935 digit = wchCurrent - 'A' + 10;
1936 } else if (wchCurrent >= 'a' && wchCurrent <= 'z') {
1937 digit = wchCurrent - 'a' + 10;
1938 } else {
1939 digit = -1;
1940 } /* if */
1941 if (digit < 0 || digit >= base) {
1942 *value = bMinus ? -RunningTotal : RunningTotal;
1943 return STATUS_SUCCESS;
1944 } /* if */
1946 RunningTotal = RunningTotal * base + digit;
1947 lpwstr++;
1948 CharsRemaining--;
1949 } /* while */
1951 *value = bMinus ? -RunningTotal : RunningTotal;
1952 return STATUS_SUCCESS;
1956 /**************************************************************************
1957 * RtlIntegerToUnicodeString (NTDLL.@)
1959 * Converts an unsigned integer to a '\0' terminated unicode string.
1961 * RETURNS
1962 * Success: STATUS_SUCCESS. str contains the converted number
1963 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1964 * STATUS_BUFFER_OVERFLOW, if str is too small to hold the string
1965 * (with the '\0' termination). In this case str->Length
1966 * is set to the length, the string would have (which can
1967 * be larger than the MaximumLength).
1969 * NOTES
1970 * Instead of base 0 it uses 10 as base.
1971 * If str is NULL it crashes, as the native function does.
1973 * DIFFERENCES
1974 * Do not return STATUS_BUFFER_OVERFLOW when the string is long enough.
1975 * The native function does this when the string would be longer than 16
1976 * characters even when the string parameter is long enough.
1978 NTSTATUS WINAPI RtlIntegerToUnicodeString(
1979 ULONG value, /* [I] Value to be converted */
1980 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1981 UNICODE_STRING *str) /* [O] Destination for the converted value */
1983 WCHAR buffer[33];
1984 PWCHAR pos;
1985 WCHAR digit;
1987 if (base == 0) {
1988 base = 10;
1989 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1990 return STATUS_INVALID_PARAMETER;
1991 } /* if */
1993 pos = &buffer[32];
1994 *pos = '\0';
1996 do {
1997 pos--;
1998 digit = value % base;
1999 value = value / base;
2000 if (digit < 10) {
2001 *pos = '0' + digit;
2002 } else {
2003 *pos = 'A' + digit - 10;
2004 } /* if */
2005 } while (value != 0L);
2007 str->Length = (&buffer[32] - pos) * sizeof(WCHAR);
2008 if (str->Length >= str->MaximumLength) {
2009 return STATUS_BUFFER_OVERFLOW;
2010 } else {
2011 memcpy(str->Buffer, pos, str->Length + sizeof(WCHAR));
2012 } /* if */
2013 return STATUS_SUCCESS;
2017 /*************************************************************************
2018 * RtlGUIDFromString (NTDLL.@)
2020 * Convert a string representation of a GUID into a GUID.
2022 * PARAMS
2023 * str [I] String representation in the format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
2024 * guid [O] Destination for the converted GUID
2026 * RETURNS
2027 * Success: STATUS_SUCCESS. guid contains the converted value.
2028 * Failure: STATUS_INVALID_PARAMETER, if str is not in the expected format.
2030 * SEE ALSO
2031 * See RtlStringFromGUID.
2033 NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING str, GUID* guid)
2035 int i = 0;
2036 const WCHAR *lpszCLSID = str->Buffer;
2037 BYTE* lpOut = (BYTE*)guid;
2039 TRACE("(%s,%p)\n", debugstr_us(str), guid);
2041 /* Convert string: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
2042 * to memory: DWORD... WORD WORD BYTES............
2044 while (i <= 37)
2046 switch (i)
2048 case 0:
2049 if (*lpszCLSID != '{')
2050 return STATUS_INVALID_PARAMETER;
2051 break;
2053 case 9: case 14: case 19: case 24:
2054 if (*lpszCLSID != '-')
2055 return STATUS_INVALID_PARAMETER;
2056 break;
2058 case 37:
2059 if (*lpszCLSID != '}')
2060 return STATUS_INVALID_PARAMETER;
2061 break;
2063 default:
2065 WCHAR ch = *lpszCLSID, ch2 = lpszCLSID[1];
2066 unsigned char byte;
2068 /* Read two hex digits as a byte value */
2069 if (ch >= '0' && ch <= '9') ch = ch - '0';
2070 else if (ch >= 'a' && ch <= 'f') ch = ch - 'a' + 10;
2071 else if (ch >= 'A' && ch <= 'F') ch = ch - 'A' + 10;
2072 else return STATUS_INVALID_PARAMETER;
2074 if (ch2 >= '0' && ch2 <= '9') ch2 = ch2 - '0';
2075 else if (ch2 >= 'a' && ch2 <= 'f') ch2 = ch2 - 'a' + 10;
2076 else if (ch2 >= 'A' && ch2 <= 'F') ch2 = ch2 - 'A' + 10;
2077 else return STATUS_INVALID_PARAMETER;
2079 byte = ch << 4 | ch2;
2081 switch (i)
2083 #ifndef WORDS_BIGENDIAN
2084 /* For Big Endian machines, we store the data such that the
2085 * dword/word members can be read as DWORDS and WORDS correctly. */
2086 /* Dword */
2087 case 1: lpOut[3] = byte; break;
2088 case 3: lpOut[2] = byte; break;
2089 case 5: lpOut[1] = byte; break;
2090 case 7: lpOut[0] = byte; lpOut += 4; break;
2091 /* Word */
2092 case 10: case 15: lpOut[1] = byte; break;
2093 case 12: case 17: lpOut[0] = byte; lpOut += 2; break;
2094 #endif
2095 /* Byte */
2096 default: lpOut[0] = byte; lpOut++; break;
2098 lpszCLSID++; /* Skip 2nd character of byte */
2099 i++;
2102 lpszCLSID++;
2103 i++;
2106 return STATUS_SUCCESS;
2109 /*************************************************************************
2110 * RtlStringFromGUID (NTDLL.@)
2112 * Convert a GUID into a string representation of a GUID.
2114 * PARAMS
2115 * guid [I] GUID to convert
2116 * str [O] Destination for the converted string
2118 * RETURNS
2119 * Success: STATUS_SUCCESS. str contains the converted value.
2120 * Failure: STATUS_NO_MEMORY, if memory for str cannot be allocated.
2122 * SEE ALSO
2123 * See RtlGUIDFromString.
2125 NTSTATUS WINAPI RtlStringFromGUID(const GUID* guid, UNICODE_STRING *str)
2127 static const WCHAR szFormat[] = { '{','%','0','8','l','X','-',
2128 '%','0','4','X','-', '%','0','4','X','-','%','0','2','X','%','0','2','X',
2129 '-', '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
2130 '%','0','2','X','%','0','2','X','}','\0' };
2132 TRACE("(%p,%p)\n", guid, str);
2134 str->Length = GUID_STRING_LENGTH * sizeof(WCHAR);
2135 str->MaximumLength = str->Length + sizeof(WCHAR);
2136 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, str->MaximumLength);
2137 if (!str->Buffer)
2139 str->Length = str->MaximumLength = 0;
2140 return STATUS_NO_MEMORY;
2142 sprintfW(str->Buffer, szFormat, guid->Data1, guid->Data2, guid->Data3,
2143 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
2144 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
2146 return STATUS_SUCCESS;
2149 /******************************************************************************
2150 * RtlHashUnicodeString [NTDLL.@]
2152 NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING string, BOOLEAN case_insensitive, ULONG alg, ULONG *hash)
2154 unsigned int i;
2156 if (!string || !hash) return STATUS_INVALID_PARAMETER;
2158 switch (alg)
2160 case HASH_STRING_ALGORITHM_DEFAULT:
2161 case HASH_STRING_ALGORITHM_X65599:
2162 break;
2163 default:
2164 return STATUS_INVALID_PARAMETER;
2167 *hash = 0;
2168 for (i = 0; i < string->Length/sizeof(WCHAR); i++)
2169 *hash = *hash*65599 + (case_insensitive ? toupperW(string->Buffer[i]) : string->Buffer[i]);
2171 return STATUS_SUCCESS;