mshtml: Don't crash creating a URI if we have no document.
[wine.git] / dlls / ntdll / rtlstr.c
blob3013658e596abefe74ef1693c6bb829c84279e8f
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;
66 int ntdll_umbstowcs(DWORD flags, const char* src, int srclen, WCHAR* dst, int dstlen)
68 #ifdef __APPLE__
69 /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
70 if (!unix_table) flags |= MB_COMPOSITE;
71 #endif
72 return (unix_table) ?
73 wine_cp_mbstowcs( unix_table, flags, src, srclen, dst, dstlen ) :
74 wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
77 int ntdll_wcstoumbs(DWORD flags, const WCHAR* src, int srclen, char* dst, int dstlen,
78 const char* defchar, int *used )
80 if (unix_table)
81 return wine_cp_wcstombs( unix_table, flags, src, srclen, dst, dstlen, defchar, used );
82 if (used) *used = 0; /* all chars are valid for UTF-8 */
83 return wine_utf8_wcstombs( flags, src, srclen, dst, dstlen );
86 /**************************************************************************
87 * RtlInitAnsiString (NTDLL.@)
89 * Initializes a buffered ansi string.
91 * RETURNS
92 * Nothing.
94 * NOTES
95 * Assigns source to target->Buffer. The length of source is assigned to
96 * target->Length and target->MaximumLength. If source is NULL the length
97 * of source is assumed to be 0.
99 void WINAPI RtlInitAnsiString(
100 PANSI_STRING target, /* [I/O] Buffered ansi string to be initialized */
101 PCSZ source) /* [I] '\0' terminated string used to initialize target */
103 if ((target->Buffer = (PCHAR) source))
105 target->Length = strlen(source);
106 target->MaximumLength = target->Length + 1;
108 else target->Length = target->MaximumLength = 0;
111 /**************************************************************************
112 * RtlInitAnsiStringEx (NTDLL.@)
114 * Initializes a buffered ansi string.
116 * RETURNS
117 * An appropriate NTSTATUS value.
119 * NOTES
120 * Assigns source to target->Buffer. The length of source is assigned to
121 * target->Length and target->MaximumLength. If source is NULL the length
122 * of source is assumed to be 0.
124 NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING target, PCSZ source)
126 if (source)
128 unsigned int len = strlen(source);
129 if (len+1 > 0xffff)
130 return STATUS_NAME_TOO_LONG;
132 target->Buffer = (PCHAR) source;
133 target->Length = len;
134 target->MaximumLength = len + 1;
136 else
138 target->Buffer = NULL;
139 target->Length = 0;
140 target->MaximumLength = 0;
142 return STATUS_SUCCESS;
145 /**************************************************************************
146 * RtlInitString (NTDLL.@)
148 * Initializes a buffered string.
150 * RETURNS
151 * Nothing.
153 * NOTES
154 * Assigns source to target->Buffer. The length of source is assigned to
155 * target->Length and target->MaximumLength. If source is NULL the length
156 * of source is assumed to be 0.
158 void WINAPI RtlInitString(
159 PSTRING target, /* [I/O] Buffered string to be initialized */
160 PCSZ source) /* [I] '\0' terminated string used to initialize target */
162 RtlInitAnsiString( target, source );
166 /**************************************************************************
167 * RtlFreeAnsiString (NTDLL.@)
169 void WINAPI RtlFreeAnsiString( PSTRING str )
171 if (str->Buffer)
173 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
174 RtlZeroMemory( str, sizeof(*str) );
179 /**************************************************************************
180 * RtlFreeOemString (NTDLL.@)
182 void WINAPI RtlFreeOemString( PSTRING str )
184 RtlFreeAnsiString( str );
188 /**************************************************************************
189 * RtlCopyString (NTDLL.@)
191 void WINAPI RtlCopyString( STRING *dst, const STRING *src )
193 if (src)
195 unsigned int len = min( src->Length, dst->MaximumLength );
196 memcpy( dst->Buffer, src->Buffer, len );
197 dst->Length = len;
199 else dst->Length = 0;
203 /**************************************************************************
204 * RtlInitUnicodeString (NTDLL.@)
206 * Initializes a buffered unicode string.
208 * RETURNS
209 * Nothing.
211 * NOTES
212 * Assigns source to target->Buffer. The length of source is assigned to
213 * target->Length and target->MaximumLength. If source is NULL the length
214 * of source is assumed to be 0.
216 void WINAPI RtlInitUnicodeString(
217 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
218 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
220 if ((target->Buffer = (PWSTR) source))
222 unsigned int length = strlenW(source) * sizeof(WCHAR);
223 if (length > 0xfffc)
224 length = 0xfffc;
225 target->Length = length;
226 target->MaximumLength = target->Length + sizeof(WCHAR);
228 else target->Length = target->MaximumLength = 0;
232 /**************************************************************************
233 * RtlInitUnicodeStringEx (NTDLL.@)
235 * Initializes a buffered unicode string.
237 * RETURNS
238 * Success: STATUS_SUCCESS. target is initialized.
239 * Failure: STATUS_NAME_TOO_LONG, if the source string is larger than 65532 bytes.
241 * NOTES
242 * Assigns source to target->Buffer. The length of source is assigned to
243 * target->Length and target->MaximumLength. If source is NULL the length
244 * of source is assumed to be 0.
246 NTSTATUS WINAPI RtlInitUnicodeStringEx(
247 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
248 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
250 if (source != NULL) {
251 unsigned int len = strlenW(source) * sizeof(WCHAR);
253 if (len > 0xFFFC) {
254 return STATUS_NAME_TOO_LONG;
255 } else {
256 target->Length = len;
257 target->MaximumLength = len + sizeof(WCHAR);
258 target->Buffer = (PWSTR) source;
259 } /* if */
260 } else {
261 target->Length = 0;
262 target->MaximumLength = 0;
263 target->Buffer = NULL;
264 } /* if */
265 return STATUS_SUCCESS;
269 /**************************************************************************
270 * RtlCreateUnicodeString (NTDLL.@)
272 * Creates a UNICODE_STRING from a null-terminated Unicode string.
274 * RETURNS
275 * Success: TRUE
276 * Failure: FALSE
278 BOOLEAN WINAPI RtlCreateUnicodeString( PUNICODE_STRING target, LPCWSTR src )
280 int len = (strlenW(src) + 1) * sizeof(WCHAR);
281 if (!(target->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return FALSE;
282 memcpy( target->Buffer, src, len );
283 target->MaximumLength = len;
284 target->Length = len - sizeof(WCHAR);
285 return TRUE;
289 /**************************************************************************
290 * RtlCreateUnicodeStringFromAsciiz (NTDLL.@)
292 * Creates a UNICODE_STRING from a null-terminated Ascii string.
294 * RETURNS
295 * Success: TRUE
296 * Failure: FALSE
298 BOOLEAN WINAPI RtlCreateUnicodeStringFromAsciiz( PUNICODE_STRING target, LPCSTR src )
300 STRING ansi;
301 RtlInitAnsiString( &ansi, src );
302 return !RtlAnsiStringToUnicodeString( target, &ansi, TRUE );
306 /**************************************************************************
307 * RtlFreeUnicodeString (NTDLL.@)
309 * Frees a UNICODE_STRING created with RtlCreateUnicodeString() or
310 * RtlCreateUnicodeStringFromAsciiz().
312 * RETURNS
313 * nothing
315 void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str )
317 if (str->Buffer)
319 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
320 RtlZeroMemory( str, sizeof(*str) );
325 /**************************************************************************
326 * RtlCopyUnicodeString (NTDLL.@)
328 * Copies from one UNICODE_STRING to another.
330 * RETURNS
331 * nothing
333 void WINAPI RtlCopyUnicodeString( UNICODE_STRING *dst, const UNICODE_STRING *src )
335 if (src)
337 unsigned int len = min( src->Length, dst->MaximumLength );
338 memcpy( dst->Buffer, src->Buffer, len );
339 dst->Length = len;
340 /* append terminating '\0' if enough space */
341 if (len < dst->MaximumLength) dst->Buffer[len / sizeof(WCHAR)] = 0;
343 else dst->Length = 0;
347 /**************************************************************************
348 * RtlDuplicateUnicodeString (NTDLL.@)
350 * Duplicates a unicode string.
352 * RETURNS
353 * Success: STATUS_SUCCESS. destination contains the duplicated unicode string.
354 * Failure: STATUS_INVALID_PARAMETER, if one of the parameters is illegal.
355 * STATUS_NO_MEMORY, if the allocation fails.
357 * NOTES
358 * For add_nul there are several possible values:
359 * 0 = destination will not be '\0' terminated,
360 * 1 = destination will be '\0' terminated,
361 * 3 = like 1 but for an empty source string produce '\0' terminated empty
362 * Buffer instead of assigning NULL to the Buffer.
363 * Other add_nul values are invalid.
365 NTSTATUS WINAPI RtlDuplicateUnicodeString(
366 int add_nul, /* [I] flag */
367 const UNICODE_STRING *source, /* [I] Unicode string to be duplicated */
368 UNICODE_STRING *destination) /* [O] destination for the duplicated unicode string */
370 if (source == NULL || destination == NULL ||
371 source->Length > source->MaximumLength ||
372 (source->Length == 0 && source->MaximumLength > 0 && source->Buffer == NULL) ||
373 add_nul == 2 || add_nul >= 4 || add_nul < 0) {
374 return STATUS_INVALID_PARAMETER;
375 } else {
376 if (source->Length == 0 && add_nul != 3) {
377 destination->Length = 0;
378 destination->MaximumLength = 0;
379 destination->Buffer = NULL;
380 } else {
381 unsigned int destination_max_len = source->Length;
383 if (add_nul) {
384 destination_max_len += sizeof(WCHAR);
385 } /* if */
386 destination->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, destination_max_len);
387 if (destination->Buffer == NULL) {
388 return STATUS_NO_MEMORY;
389 } else {
390 memcpy(destination->Buffer, source->Buffer, source->Length);
391 destination->Length = source->Length;
392 destination->MaximumLength = source->Length;
393 /* append terminating '\0' if enough space */
394 if (add_nul) {
395 destination->MaximumLength = destination_max_len;
396 destination->Buffer[destination->Length / sizeof(WCHAR)] = 0;
397 } /* if */
398 } /* if */
399 } /* if */
400 } /* if */
401 return STATUS_SUCCESS;
405 /**************************************************************************
406 * RtlEraseUnicodeString (NTDLL.@)
408 * Overwrites a UNICODE_STRING with zeros.
410 * RETURNS
411 * nothing
413 void WINAPI RtlEraseUnicodeString( UNICODE_STRING *str )
415 if (str->Buffer)
417 memset( str->Buffer, 0, str->MaximumLength );
418 str->Length = 0;
424 COMPARISON FUNCTIONS
428 /******************************************************************************
429 * RtlCompareString (NTDLL.@)
431 LONG WINAPI RtlCompareString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
433 unsigned int len;
434 LONG ret = 0;
435 LPCSTR p1, p2;
437 len = min(s1->Length, s2->Length);
438 p1 = s1->Buffer;
439 p2 = s2->Buffer;
441 if (CaseInsensitive)
443 while (!ret && len--) ret = RtlUpperChar(*p1++) - RtlUpperChar(*p2++);
445 else
447 while (!ret && len--) ret = *p1++ - *p2++;
449 if (!ret) ret = s1->Length - s2->Length;
450 return ret;
454 /******************************************************************************
455 * RtlCompareUnicodeStrings (NTDLL.@)
457 LONG WINAPI RtlCompareUnicodeStrings( const WCHAR *s1, SIZE_T len1, const WCHAR *s2, SIZE_T len2,
458 BOOLEAN case_insensitive )
460 LONG ret = 0;
461 SIZE_T len = min( len1, len2 );
463 if (case_insensitive)
465 while (!ret && len--) ret = toupperW(*s1++) - toupperW(*s2++);
467 else
469 while (!ret && len--) ret = *s1++ - *s2++;
471 if (!ret) ret = len1 - len2;
472 return ret;
476 /******************************************************************************
477 * RtlCompareUnicodeString (NTDLL.@)
479 LONG WINAPI RtlCompareUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
480 BOOLEAN CaseInsensitive )
482 return RtlCompareUnicodeStrings( s1->Buffer, s1->Length / sizeof(WCHAR),
483 s2->Buffer, s2->Length / sizeof(WCHAR), CaseInsensitive );
487 /**************************************************************************
488 * RtlEqualString (NTDLL.@)
490 * Determine if two strings are equal.
492 * PARAMS
493 * s1 [I] Source string
494 * s2 [I] String to compare to s1
495 * CaseInsensitive [I] TRUE = Case insensitive, FALSE = Case sensitive
497 * RETURNS
498 * Non-zero if s1 is equal to s2, 0 otherwise.
500 BOOLEAN WINAPI RtlEqualString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
502 if (s1->Length != s2->Length) return FALSE;
503 return !RtlCompareString( s1, s2, CaseInsensitive );
507 /**************************************************************************
508 * RtlEqualUnicodeString (NTDLL.@)
510 * Unicode version of RtlEqualString.
512 BOOLEAN WINAPI RtlEqualUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
513 BOOLEAN CaseInsensitive )
515 if (s1->Length != s2->Length) return FALSE;
516 return !RtlCompareUnicodeString( s1, s2, CaseInsensitive );
520 /**************************************************************************
521 * RtlPrefixString (NTDLL.@)
523 * Determine if one string is a prefix of another.
525 * PARAMS
526 * s1 [I] Prefix to look for in s2
527 * s2 [I] String that may contain s1 as a prefix
528 * ignore_case [I] TRUE = Case insensitive, FALSE = Case sensitive
530 * RETURNS
531 * TRUE if s2 contains s1 as a prefix, FALSE otherwise.
533 BOOLEAN WINAPI RtlPrefixString( const STRING *s1, const STRING *s2, BOOLEAN ignore_case )
535 unsigned int i;
537 if (s1->Length > s2->Length) return FALSE;
538 if (ignore_case)
540 for (i = 0; i < s1->Length; i++)
541 if (RtlUpperChar(s1->Buffer[i]) != RtlUpperChar(s2->Buffer[i])) return FALSE;
543 else
545 for (i = 0; i < s1->Length; i++)
546 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
548 return TRUE;
552 /**************************************************************************
553 * RtlPrefixUnicodeString (NTDLL.@)
555 * Unicode version of RtlPrefixString.
557 BOOLEAN WINAPI RtlPrefixUnicodeString( const UNICODE_STRING *s1,
558 const UNICODE_STRING *s2,
559 BOOLEAN ignore_case )
561 unsigned int i;
563 if (s1->Length > s2->Length) return FALSE;
564 if (ignore_case)
566 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
567 if (toupperW(s1->Buffer[i]) != toupperW(s2->Buffer[i])) return FALSE;
569 else
571 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
572 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
574 return TRUE;
578 /**************************************************************************
579 * RtlEqualComputerName (NTDLL.@)
581 * Determine if two computer names are the same.
583 * PARAMS
584 * left [I] First computer name
585 * right [I] Second computer name
587 * RETURNS
588 * 0 if the names are equal, non-zero otherwise.
590 * NOTES
591 * The comparison is case insensitive.
593 NTSTATUS WINAPI RtlEqualComputerName(const UNICODE_STRING *left,
594 const UNICODE_STRING *right)
596 NTSTATUS ret;
597 STRING upLeft, upRight;
599 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upLeft, left, TRUE )))
601 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upRight, right, TRUE )))
603 ret = RtlEqualString( &upLeft, &upRight, FALSE );
604 RtlFreeOemString( &upRight );
606 RtlFreeOemString( &upLeft );
608 return ret;
612 /**************************************************************************
613 * RtlEqualDomainName (NTDLL.@)
615 * Determine if two domain names are the same.
617 * PARAMS
618 * left [I] First domain name
619 * right [I] Second domain name
621 * RETURNS
622 * 0 if the names are equal, non-zero otherwise.
624 * NOTES
625 * The comparison is case insensitive.
627 NTSTATUS WINAPI RtlEqualDomainName(const UNICODE_STRING *left,
628 const UNICODE_STRING *right)
630 return RtlEqualComputerName(left, right);
634 /**************************************************************************
635 * RtlAnsiCharToUnicodeChar (NTDLL.@)
637 * Converts the first ansi character to a unicode character.
639 * PARAMS
640 * ansi [I/O] Pointer to the ansi string.
642 * RETURNS
643 * Unicode representation of the first character in the ansi string.
645 * NOTES
646 * Upon successful completion, the char pointer ansi points to is
647 * incremented by the size of the character.
649 WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *ansi)
651 WCHAR str;
652 DWORD charSize = sizeof(CHAR);
654 if (wine_is_dbcs_leadbyte(ansi_table, **ansi))
655 charSize++;
657 RtlMultiByteToUnicodeN(&str, sizeof(WCHAR), NULL, *ansi, charSize);
658 *ansi += charSize;
660 return str;
664 COPY BETWEEN ANSI_STRING or UNICODE_STRING
665 there is no parameter checking, it just crashes
669 /**************************************************************************
670 * RtlAnsiStringToUnicodeString (NTDLL.@)
672 * Converts an ansi string to a unicode string.
674 * RETURNS
675 * Success: STATUS_SUCCESS. uni contains the converted string
676 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
677 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
678 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
680 * NOTES
681 * This function always writes a terminating '\0'.
683 NTSTATUS WINAPI RtlAnsiStringToUnicodeString(
684 PUNICODE_STRING uni, /* [I/O] Destination for the unicode string */
685 PCANSI_STRING ansi, /* [I] Ansi string to be converted */
686 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
688 DWORD total = RtlAnsiStringToUnicodeSize( ansi );
690 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
691 uni->Length = total - sizeof(WCHAR);
692 if (doalloc)
694 uni->MaximumLength = total;
695 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
696 return STATUS_NO_MEMORY;
698 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
700 RtlMultiByteToUnicodeN( uni->Buffer, uni->Length, NULL, ansi->Buffer, ansi->Length );
701 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
702 return STATUS_SUCCESS;
706 /**************************************************************************
707 * RtlOemStringToUnicodeString (NTDLL.@)
709 * Converts an oem string to a unicode string.
711 * RETURNS
712 * Success: STATUS_SUCCESS. uni contains the converted string
713 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
714 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
715 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
717 * NOTES
718 * This function always writes a terminating '\0'.
720 NTSTATUS WINAPI RtlOemStringToUnicodeString(
721 UNICODE_STRING *uni, /* [I/O] Destination for the unicode string */
722 const STRING *oem, /* [I] Oem string to be converted */
723 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
725 DWORD total = RtlOemStringToUnicodeSize( oem );
727 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
728 uni->Length = total - sizeof(WCHAR);
729 if (doalloc)
731 uni->MaximumLength = total;
732 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
733 return STATUS_NO_MEMORY;
735 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
737 RtlOemToUnicodeN( uni->Buffer, uni->Length, NULL, oem->Buffer, oem->Length );
738 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
739 return STATUS_SUCCESS;
743 /**************************************************************************
744 * RtlUnicodeStringToAnsiString (NTDLL.@)
746 * Converts a unicode string to an ansi string.
748 * RETURNS
749 * Success: STATUS_SUCCESS. ansi contains the converted string
750 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
751 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
753 * NOTES
754 * This function always writes a terminating '\0'.
755 * It performs a partial copy if ansi is too small.
757 NTSTATUS WINAPI RtlUnicodeStringToAnsiString(
758 STRING *ansi, /* [I/O] Destination for the ansi string */
759 const UNICODE_STRING *uni, /* [I] Unicode string to be converted */
760 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for ansi, FALSE=Use existing buffer */
762 NTSTATUS ret = STATUS_SUCCESS;
763 DWORD len = RtlUnicodeStringToAnsiSize( uni );
765 ansi->Length = len - 1;
766 if (doalloc)
768 ansi->MaximumLength = len;
769 if (!(ansi->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
770 return STATUS_NO_MEMORY;
772 else if (ansi->MaximumLength < len)
774 if (!ansi->MaximumLength) return STATUS_BUFFER_OVERFLOW;
775 ansi->Length = ansi->MaximumLength - 1;
776 ret = STATUS_BUFFER_OVERFLOW;
779 RtlUnicodeToMultiByteN( ansi->Buffer, ansi->Length, NULL, uni->Buffer, uni->Length );
780 ansi->Buffer[ansi->Length] = 0;
781 return ret;
785 /**************************************************************************
786 * RtlUnicodeStringToOemString (NTDLL.@)
788 * Converts a Rtl Unicode string to an OEM string.
790 * PARAMS
791 * oem [O] Destination for OEM string
792 * uni [I] Source Unicode string
793 * doalloc [I] TRUE=Allocate new buffer for oem,FALSE=Use existing buffer
795 * RETURNS
796 * Success: STATUS_SUCCESS. oem contains the converted string
797 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
798 * STATUS_NO_MEMORY, if doalloc is TRUE and allocation fails.
800 * NOTES
801 * If doalloc is TRUE, the length allocated is uni->Length + 1.
802 * This function always '\0' terminates the string returned.
804 NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
805 const UNICODE_STRING *uni,
806 BOOLEAN doalloc )
808 NTSTATUS ret = STATUS_SUCCESS;
809 DWORD len = RtlUnicodeStringToOemSize( uni );
811 oem->Length = len - 1;
812 if (doalloc)
814 oem->MaximumLength = len;
815 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
816 return STATUS_NO_MEMORY;
818 else if (oem->MaximumLength < len)
820 if (!oem->MaximumLength) return STATUS_BUFFER_OVERFLOW;
821 oem->Length = oem->MaximumLength - 1;
822 ret = STATUS_BUFFER_OVERFLOW;
825 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, uni->Buffer, uni->Length );
826 oem->Buffer[oem->Length] = 0;
827 return ret;
831 /**************************************************************************
832 * RtlMultiByteToUnicodeN (NTDLL.@)
834 * Converts a multi-byte string to a Unicode string.
836 * RETURNS
837 * NTSTATUS code
839 * NOTES
840 * Performs a partial copy if dst is too small.
842 NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
843 LPCSTR src, DWORD srclen )
846 int ret = wine_cp_mbstowcs( ansi_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
847 if (reslen)
848 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
849 return STATUS_SUCCESS;
853 /**************************************************************************
854 * RtlOemToUnicodeN (NTDLL.@)
856 * Converts a multi-byte string in the OEM code page to a Unicode string.
858 * RETURNS
859 * NTSTATUS code
861 NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
862 LPCSTR src, DWORD srclen )
864 int ret = wine_cp_mbstowcs( oem_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
865 if (reslen)
866 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
867 return STATUS_SUCCESS;
871 /**************************************************************************
872 * RtlUnicodeToMultiByteN (NTDLL.@)
874 * Converts a Unicode string to a multi-byte string in the ANSI code page.
876 * RETURNS
877 * NTSTATUS code
879 NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
880 LPCWSTR src, DWORD srclen )
882 int ret = wine_cp_wcstombs( ansi_table, 0, src, srclen / sizeof(WCHAR),
883 dst, dstlen, NULL, NULL );
884 if (reslen)
885 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
886 return STATUS_SUCCESS;
890 /**************************************************************************
891 * RtlUnicodeToOemN (NTDLL.@)
893 * Converts a Unicode string to a multi-byte string in the OEM code page.
895 * RETURNS
896 * NTSTATUS code
898 NTSTATUS WINAPI RtlUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
899 LPCWSTR src, DWORD srclen )
901 int ret = wine_cp_wcstombs( oem_table, 0, src, srclen / sizeof(WCHAR),
902 dst, dstlen, NULL, NULL );
903 if (reslen)
904 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
905 return STATUS_SUCCESS;
910 CASE CONVERSIONS
914 /**************************************************************************
915 * RtlUpperChar (NTDLL.@)
917 * Converts an Ascii character to uppercase.
919 * PARAMS
920 * ch [I] Character to convert
922 * RETURNS
923 * The uppercase character value.
925 * NOTES
926 * For the input characters from 'a' .. 'z' it returns 'A' .. 'Z'.
927 * All other input characters are returned unchanged. The locale and
928 * multibyte characters are not taken into account (as native DLL).
930 CHAR WINAPI RtlUpperChar( CHAR ch )
932 if (ch >= 'a' && ch <= 'z') {
933 return ch - 'a' + 'A';
934 } else {
935 return ch;
936 } /* if */
940 /**************************************************************************
941 * RtlUpperString (NTDLL.@)
943 * Converts an Ascii string to uppercase.
945 * PARAMS
946 * dst [O] Destination for converted string
947 * src [I] Source string to convert
949 * RETURNS
950 * Nothing.
952 * NOTES
953 * For the src characters from 'a' .. 'z' it assigns 'A' .. 'Z' to dst.
954 * All other src characters are copied unchanged to dst. The locale and
955 * multibyte characters are not taken into account (as native DLL).
956 * The number of character copied is the minimum of src->Length and
957 * the dst->MaximumLength.
959 void WINAPI RtlUpperString( STRING *dst, const STRING *src )
961 unsigned int i, len = min(src->Length, dst->MaximumLength);
963 for (i = 0; i < len; i++) dst->Buffer[i] = RtlUpperChar(src->Buffer[i]);
964 dst->Length = len;
968 /**************************************************************************
969 * RtlUpcaseUnicodeChar (NTDLL.@)
971 * Converts a Unicode character to uppercase.
973 * PARAMS
974 * wch [I] Character to convert
976 * RETURNS
977 * The uppercase character value.
979 WCHAR WINAPI RtlUpcaseUnicodeChar( WCHAR wch )
981 return toupperW(wch);
985 /**************************************************************************
986 * RtlDowncaseUnicodeChar (NTDLL.@)
988 * Converts a Unicode character to lowercase.
990 * PARAMS
991 * wch [I] Character to convert
993 * RETURNS
994 * The lowercase character value.
996 WCHAR WINAPI RtlDowncaseUnicodeChar(WCHAR wch)
998 return tolowerW(wch);
1002 /**************************************************************************
1003 * RtlUpcaseUnicodeString (NTDLL.@)
1005 * Converts a Unicode string to uppercase.
1007 * PARAMS
1008 * dest [O] Destination for converted string
1009 * src [I] Source string to convert
1010 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1012 * RETURNS
1013 * Success: STATUS_SUCCESS. dest contains the converted string.
1014 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1015 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1017 * NOTES
1018 * dest is never '\0' terminated because it may be equal to src, and src
1019 * might not be '\0' terminated. dest->Length is only set upon success.
1021 NTSTATUS WINAPI RtlUpcaseUnicodeString( UNICODE_STRING *dest,
1022 const UNICODE_STRING *src,
1023 BOOLEAN doalloc)
1025 DWORD i, len = src->Length;
1027 if (doalloc)
1029 dest->MaximumLength = len;
1030 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1031 return STATUS_NO_MEMORY;
1033 else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
1035 for (i = 0; i < len/sizeof(WCHAR); i++) dest->Buffer[i] = toupperW(src->Buffer[i]);
1036 dest->Length = len;
1037 return STATUS_SUCCESS;
1041 /**************************************************************************
1042 * RtlDowncaseUnicodeString (NTDLL.@)
1044 * Converts a Unicode string to lowercase.
1046 * PARAMS
1047 * dest [O] Destination for converted string
1048 * src [I] Source string to convert
1049 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1051 * RETURNS
1052 * Success: STATUS_SUCCESS. dest contains the converted string.
1053 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1054 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1056 * NOTES
1057 * dest is never '\0' terminated because it may be equal to src, and src
1058 * might not be '\0' terminated. dest->Length is only set upon success.
1060 NTSTATUS WINAPI RtlDowncaseUnicodeString(
1061 UNICODE_STRING *dest,
1062 const UNICODE_STRING *src,
1063 BOOLEAN doalloc)
1065 DWORD i;
1066 DWORD len = src->Length;
1068 if (doalloc) {
1069 dest->MaximumLength = len;
1070 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) {
1071 return STATUS_NO_MEMORY;
1072 } /* if */
1073 } else if (len > dest->MaximumLength) {
1074 return STATUS_BUFFER_OVERFLOW;
1075 } /* if */
1077 for (i = 0; i < len/sizeof(WCHAR); i++) {
1078 dest->Buffer[i] = tolowerW(src->Buffer[i]);
1079 } /* for */
1080 dest->Length = len;
1081 return STATUS_SUCCESS;
1085 /**************************************************************************
1086 * RtlUpcaseUnicodeStringToAnsiString (NTDLL.@)
1088 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1090 * RETURNS
1091 * NTSTATUS code
1093 * NOTES
1094 * writes terminating 0
1096 NTSTATUS WINAPI RtlUpcaseUnicodeStringToAnsiString( STRING *dst,
1097 const UNICODE_STRING *src,
1098 BOOLEAN doalloc )
1100 NTSTATUS ret;
1101 UNICODE_STRING upcase;
1103 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1105 ret = RtlUnicodeStringToAnsiString( dst, &upcase, doalloc );
1106 RtlFreeUnicodeString( &upcase );
1108 return ret;
1112 /**************************************************************************
1113 * RtlUpcaseUnicodeStringToOemString (NTDLL.@)
1115 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1116 * stored in STRING format.
1118 * RETURNS
1119 * NTSTATUS code
1121 * NOTES
1122 * writes terminating 0
1124 NTSTATUS WINAPI RtlUpcaseUnicodeStringToOemString( STRING *dst,
1125 const UNICODE_STRING *src,
1126 BOOLEAN doalloc )
1128 NTSTATUS ret;
1129 UNICODE_STRING upcase;
1131 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1133 ret = RtlUnicodeStringToOemString( dst, &upcase, doalloc );
1134 RtlFreeUnicodeString( &upcase );
1136 return ret;
1140 /**************************************************************************
1141 * RtlUpcaseUnicodeStringToCountedOemString (NTDLL.@)
1143 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1144 * stored in STRING format.
1146 * RETURNS
1147 * NTSTATUS code
1149 * NOTES
1150 * Same as RtlUpcaseUnicodeStringToOemString but doesn't write terminating null
1152 NTSTATUS WINAPI RtlUpcaseUnicodeStringToCountedOemString( STRING *oem,
1153 const UNICODE_STRING *uni,
1154 BOOLEAN doalloc )
1156 NTSTATUS ret;
1157 UNICODE_STRING upcase;
1158 WCHAR tmp[32];
1160 upcase.Buffer = tmp;
1161 upcase.MaximumLength = sizeof(tmp);
1162 ret = RtlUpcaseUnicodeString( &upcase, uni, FALSE );
1163 if (ret == STATUS_BUFFER_OVERFLOW) ret = RtlUpcaseUnicodeString( &upcase, uni, TRUE );
1165 if (!ret)
1167 DWORD len = RtlUnicodeStringToOemSize( &upcase ) - 1;
1168 oem->Length = len;
1169 if (doalloc)
1171 oem->MaximumLength = len;
1172 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1174 ret = STATUS_NO_MEMORY;
1175 goto done;
1178 else if (oem->MaximumLength < len)
1180 ret = STATUS_BUFFER_OVERFLOW;
1181 oem->Length = oem->MaximumLength;
1182 if (!oem->MaximumLength) goto done;
1184 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, upcase.Buffer, upcase.Length );
1185 done:
1186 if (upcase.Buffer != tmp) RtlFreeUnicodeString( &upcase );
1188 return ret;
1192 /**************************************************************************
1193 * RtlUpcaseUnicodeToMultiByteN (NTDLL.@)
1195 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1197 * RETURNS
1198 * NTSTATUS code
1200 NTSTATUS WINAPI RtlUpcaseUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1201 LPCWSTR src, DWORD srclen )
1203 NTSTATUS ret;
1204 LPWSTR upcase;
1205 DWORD i;
1207 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1208 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1209 ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen );
1210 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1211 return ret;
1215 /**************************************************************************
1216 * RtlUpcaseUnicodeToOemN (NTDLL.@)
1218 * Converts a Unicode string to the equivalent OEM upper-case representation.
1220 * RETURNS
1221 * NTSTATUS code
1223 NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1224 LPCWSTR src, DWORD srclen )
1226 NTSTATUS ret;
1227 LPWSTR upcase;
1228 DWORD i;
1230 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1231 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1232 ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen );
1233 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1234 return ret;
1239 STRING SIZE
1243 /**************************************************************************
1244 * RtlOemStringToUnicodeSize (NTDLL.@)
1245 * RtlxOemStringToUnicodeSize (NTDLL.@)
1247 * Calculate the size in bytes necessary for the Unicode conversion of str,
1248 * including the terminating '\0'.
1250 * PARAMS
1251 * str [I] String to calculate the size of
1253 * RETURNS
1254 * The calculated size.
1256 UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str )
1258 int ret = wine_cp_mbstowcs( oem_table, 0, str->Buffer, str->Length, NULL, 0 );
1259 return (ret + 1) * sizeof(WCHAR);
1263 /**************************************************************************
1264 * RtlAnsiStringToUnicodeSize (NTDLL.@)
1265 * RtlxAnsiStringToUnicodeSize (NTDLL.@)
1267 * Calculate the size in bytes necessary for the Unicode conversion of str,
1268 * including the terminating '\0'.
1270 * PARAMS
1271 * str [I] String to calculate the size of
1273 * RETURNS
1274 * The calculated size.
1276 DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str )
1278 DWORD ret;
1279 RtlMultiByteToUnicodeSize( &ret, str->Buffer, str->Length );
1280 return ret + sizeof(WCHAR);
1284 /**************************************************************************
1285 * RtlMultiByteToUnicodeSize (NTDLL.@)
1287 * Compute the size in bytes necessary for the Unicode conversion of str,
1288 * without the terminating '\0'.
1290 * PARAMS
1291 * size [O] Destination for size
1292 * str [I] String to calculate the size of
1293 * len [I] Length of str
1295 * RETURNS
1296 * STATUS_SUCCESS.
1298 NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
1300 *size = wine_cp_mbstowcs( ansi_table, 0, str, len, NULL, 0 ) * sizeof(WCHAR);
1301 return STATUS_SUCCESS;
1305 /**************************************************************************
1306 * RtlUnicodeToMultiByteSize (NTDLL.@)
1308 * Calculate the size in bytes necessary for the multibyte conversion of str,
1309 * without the terminating '\0'.
1311 * PARAMS
1312 * size [O] Destination for size
1313 * str [I] String to calculate the size of
1314 * len [I] Length of str
1316 * RETURNS
1317 * STATUS_SUCCESS.
1319 NTSTATUS WINAPI RtlUnicodeToMultiByteSize( PULONG size, LPCWSTR str, ULONG len )
1321 *size = wine_cp_wcstombs( ansi_table, 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL );
1322 return STATUS_SUCCESS;
1326 /**************************************************************************
1327 * RtlUnicodeStringToAnsiSize (NTDLL.@)
1328 * RtlxUnicodeStringToAnsiSize (NTDLL.@)
1330 * Calculate the size in bytes necessary for the Ansi conversion of str,
1331 * including the terminating '\0'.
1333 * PARAMS
1334 * str [I] String to calculate the size of
1336 * RETURNS
1337 * The calculated size.
1339 DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
1341 DWORD ret;
1342 RtlUnicodeToMultiByteSize( &ret, str->Buffer, str->Length );
1343 return ret + 1;
1347 /**************************************************************************
1348 * RtlUnicodeStringToOemSize (NTDLL.@)
1349 * RtlxUnicodeStringToOemSize (NTDLL.@)
1351 * Calculate the size in bytes necessary for the OEM conversion of str,
1352 * including the terminating '\0'.
1354 * PARAMS
1355 * str [I] String to calculate the size of
1357 * RETURNS
1358 * The calculated size.
1360 DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str )
1362 return wine_cp_wcstombs( oem_table, 0, str->Buffer, str->Length / sizeof(WCHAR),
1363 NULL, 0, NULL, NULL ) + 1;
1367 /**************************************************************************
1368 * RtlAppendAsciizToString (NTDLL.@)
1370 * Concatenates a buffered character string and a '\0' terminated character
1371 * string
1373 * RETURNS
1374 * Success: STATUS_SUCCESS. src is appended to dest.
1375 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1376 * to hold the concatenated string.
1378 * NOTES
1379 * if src is NULL dest is unchanged.
1380 * dest is never '\0' terminated.
1382 NTSTATUS WINAPI RtlAppendAsciizToString(
1383 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1384 LPCSTR src) /* [I] '\0' terminated character string to be concatenated */
1386 if (src != NULL) {
1387 unsigned int src_len = strlen(src);
1388 unsigned int dest_len = src_len + dest->Length;
1390 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1391 memcpy(dest->Buffer + dest->Length, src, src_len);
1392 dest->Length = dest_len;
1393 } /* if */
1394 return STATUS_SUCCESS;
1398 /**************************************************************************
1399 * RtlAppendStringToString (NTDLL.@)
1401 * Concatenates two buffered character strings
1403 * RETURNS
1404 * Success: STATUS_SUCCESS. src is appended to dest.
1405 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1406 * to hold the concatenated string.
1408 * NOTES
1409 * if src->length is zero dest is unchanged.
1410 * dest is never '\0' terminated.
1412 NTSTATUS WINAPI RtlAppendStringToString(
1413 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1414 const STRING *src) /* [I] Buffered character string to be concatenated */
1416 if (src->Length != 0) {
1417 unsigned int dest_len = src->Length + dest->Length;
1419 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1420 memcpy(dest->Buffer + dest->Length, src->Buffer, src->Length);
1421 dest->Length = dest_len;
1422 } /* if */
1423 return STATUS_SUCCESS;
1427 /**************************************************************************
1428 * RtlAppendUnicodeToString (NTDLL.@)
1430 * Concatenates a buffered unicode string and a '\0' terminated unicode
1431 * string
1433 * RETURNS
1434 * Success: STATUS_SUCCESS. src is appended to dest.
1435 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1436 * to hold the concatenated string.
1438 * NOTES
1439 * if src is NULL dest is unchanged.
1440 * dest is '\0' terminated when the MaximumLength allows it.
1441 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1443 * DIFFERENCES
1444 * Does not write in the src->Buffer beyond MaximumLength when
1445 * MaximumLength is odd as the native function does.
1447 NTSTATUS WINAPI RtlAppendUnicodeToString(
1448 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1449 LPCWSTR src) /* [I] '\0' terminated unicode string to be concatenated */
1451 if (src != NULL) {
1452 unsigned int src_len = strlenW(src) * sizeof(WCHAR);
1453 unsigned int dest_len = src_len + dest->Length;
1455 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1456 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src, src_len);
1457 dest->Length = dest_len;
1458 /* append terminating '\0' if enough space */
1459 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1460 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1461 } /* if */
1462 } /* if */
1463 return STATUS_SUCCESS;
1467 /**************************************************************************
1468 * RtlAppendUnicodeStringToString (NTDLL.@)
1470 * Concatenates two buffered unicode strings
1472 * RETURNS
1473 * Success: STATUS_SUCCESS. src is appended to dest.
1474 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1475 * to hold the concatenated string.
1477 * NOTES
1478 * if src->length is zero dest is unchanged.
1479 * dest is '\0' terminated when the MaximumLength allows it.
1480 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1482 * DIFFERENCES
1483 * Does not write in the src->Buffer beyond MaximumLength when
1484 * MaximumLength is odd as the native function does.
1486 NTSTATUS WINAPI RtlAppendUnicodeStringToString(
1487 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1488 const UNICODE_STRING *src) /* [I] Buffered unicode string to be concatenated */
1490 if (src->Length != 0) {
1491 unsigned int dest_len = src->Length + dest->Length;
1493 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1494 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src->Buffer, src->Length);
1495 dest->Length = dest_len;
1496 /* append terminating '\0' if enough space */
1497 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1498 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1499 } /* if */
1500 } /* if */
1501 return STATUS_SUCCESS;
1505 /**************************************************************************
1506 * RtlFindCharInUnicodeString (NTDLL.@)
1508 * Searches for one of several unicode characters in a unicode string.
1510 * RETURNS
1511 * Success: STATUS_SUCCESS. pos contains the position after the character found.
1512 * Failure: STATUS_NOT_FOUND, if none of the search_chars are in main_str.
1514 NTSTATUS WINAPI RtlFindCharInUnicodeString(
1515 int flags, /* [I] Flags */
1516 const UNICODE_STRING *main_str, /* [I] Unicode string in which one or more characters are searched */
1517 const UNICODE_STRING *search_chars, /* [I] Unicode string which contains the characters to search for */
1518 USHORT *pos) /* [O] Position of the first character found + 2 */
1520 unsigned int main_idx, search_idx;
1522 switch (flags) {
1523 case 0:
1524 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1525 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1526 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1527 *pos = (main_idx + 1) * sizeof(WCHAR);
1528 return STATUS_SUCCESS;
1532 *pos = 0;
1533 return STATUS_NOT_FOUND;
1534 case 1:
1535 main_idx = main_str->Length / sizeof(WCHAR);
1536 while (main_idx-- > 0) {
1537 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1538 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1539 *pos = main_idx * sizeof(WCHAR);
1540 return STATUS_SUCCESS;
1544 *pos = 0;
1545 return STATUS_NOT_FOUND;
1546 case 2:
1547 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1548 search_idx = 0;
1549 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1550 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1551 search_idx++;
1553 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1554 *pos = (main_idx + 1) * sizeof(WCHAR);
1555 return STATUS_SUCCESS;
1558 *pos = 0;
1559 return STATUS_NOT_FOUND;
1560 case 3:
1561 main_idx = main_str->Length / sizeof(WCHAR);
1562 while (main_idx-- > 0) {
1563 search_idx = 0;
1564 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1565 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1566 search_idx++;
1568 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1569 *pos = main_idx * sizeof(WCHAR);
1570 return STATUS_SUCCESS;
1573 *pos = 0;
1574 return STATUS_NOT_FOUND;
1575 } /* switch */
1576 return STATUS_NOT_FOUND;
1581 MISC
1584 /**************************************************************************
1585 * RtlIsTextUnicode (NTDLL.@)
1587 * Attempt to guess whether a text buffer is Unicode.
1589 * PARAMS
1590 * buf [I] Text buffer to test
1591 * len [I] Length of buf
1592 * pf [O] Destination for test results
1594 * RETURNS
1595 * TRUE if the buffer is likely Unicode, FALSE otherwise.
1597 * FIXME
1598 * Should implement more tests.
1600 BOOLEAN WINAPI RtlIsTextUnicode( LPCVOID buf, INT len, INT *pf )
1602 static const WCHAR std_control_chars[] = {'\r','\n','\t',' ',0x3000,0};
1603 static const WCHAR byterev_control_chars[] = {0x0d00,0x0a00,0x0900,0x2000,0};
1604 const WCHAR *s = buf;
1605 int i;
1606 unsigned int flags = ~0U, out_flags = 0;
1608 if (len < sizeof(WCHAR))
1610 /* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
1611 if (pf) *pf = 0;
1612 return FALSE;
1614 if (pf)
1615 flags = *pf;
1617 * Apply various tests to the text string. According to the
1618 * docs, each test "passed" sets the corresponding flag in
1619 * the output flags. But some of the tests are mutually
1620 * exclusive, so I don't see how you could pass all tests ...
1623 /* Check for an odd length ... pass if even. */
1624 if (len & 1) out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
1626 if (((const char *)buf)[len - 1] == 0)
1627 len--; /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES */
1629 len /= sizeof(WCHAR);
1630 /* Windows only checks the first 256 characters */
1631 if (len > 256) len = 256;
1633 /* Check for the special byte order unicode marks. */
1634 if (*s == 0xFEFF) out_flags |= IS_TEXT_UNICODE_SIGNATURE;
1635 if (*s == 0xFFFE) out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
1637 /* apply some statistical analysis */
1638 if (flags & IS_TEXT_UNICODE_STATISTICS)
1640 int stats = 0;
1641 /* FIXME: checks only for ASCII characters in the unicode stream */
1642 for (i = 0; i < len; i++)
1644 if (s[i] <= 255) stats++;
1646 if (stats > len / 2)
1647 out_flags |= IS_TEXT_UNICODE_STATISTICS;
1650 /* Check for unicode NULL chars */
1651 if (flags & IS_TEXT_UNICODE_NULL_BYTES)
1653 for (i = 0; i < len; i++)
1655 if (!(s[i] & 0xff) || !(s[i] >> 8))
1657 out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
1658 break;
1663 if (flags & IS_TEXT_UNICODE_CONTROLS)
1665 for (i = 0; i < len; i++)
1667 if (strchrW(std_control_chars, s[i]))
1669 out_flags |= IS_TEXT_UNICODE_CONTROLS;
1670 break;
1675 if (flags & IS_TEXT_UNICODE_REVERSE_CONTROLS)
1677 for (i = 0; i < len; i++)
1679 if (strchrW(byterev_control_chars, s[i]))
1681 out_flags |= IS_TEXT_UNICODE_REVERSE_CONTROLS;
1682 break;
1687 if (pf)
1689 out_flags &= *pf;
1690 *pf = out_flags;
1692 /* check for flags that indicate it's definitely not valid Unicode */
1693 if (out_flags & (IS_TEXT_UNICODE_REVERSE_MASK | IS_TEXT_UNICODE_NOT_UNICODE_MASK)) return FALSE;
1694 /* now check for invalid ASCII, and assume Unicode if so */
1695 if (out_flags & IS_TEXT_UNICODE_NOT_ASCII_MASK) return TRUE;
1696 /* now check for Unicode flags */
1697 if (out_flags & IS_TEXT_UNICODE_UNICODE_MASK) return TRUE;
1698 /* no flags set */
1699 return FALSE;
1703 /**************************************************************************
1704 * RtlCharToInteger (NTDLL.@)
1706 * Converts a character string into its integer equivalent.
1708 * RETURNS
1709 * Success: STATUS_SUCCESS. value contains the converted number
1710 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1711 * STATUS_ACCESS_VIOLATION, if value is NULL.
1713 * NOTES
1714 * For base 0 it uses 10 as base and the string should be in the format
1715 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1716 * For other bases the string should be in the format
1717 * "{whitespace} [+|-] {digits}".
1718 * No check is made for value overflow, only the lower 32 bits are assigned.
1719 * If str is NULL it crashes, as the native function does.
1721 * DIFFERENCES
1722 * This function does not read garbage behind '\0' as the native version does.
1724 NTSTATUS WINAPI RtlCharToInteger(
1725 PCSZ str, /* [I] '\0' terminated single-byte string containing a number */
1726 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1727 ULONG *value) /* [O] Destination for the converted value */
1729 CHAR chCurrent;
1730 int digit;
1731 ULONG RunningTotal = 0;
1732 BOOL bMinus = FALSE;
1734 while (*str != '\0' && *str <= ' ') {
1735 str++;
1736 } /* while */
1738 if (*str == '+') {
1739 str++;
1740 } else if (*str == '-') {
1741 bMinus = TRUE;
1742 str++;
1743 } /* if */
1745 if (base == 0) {
1746 base = 10;
1747 if (str[0] == '0') {
1748 if (str[1] == 'b') {
1749 str += 2;
1750 base = 2;
1751 } else if (str[1] == 'o') {
1752 str += 2;
1753 base = 8;
1754 } else if (str[1] == 'x') {
1755 str += 2;
1756 base = 16;
1757 } /* if */
1758 } /* if */
1759 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1760 return STATUS_INVALID_PARAMETER;
1761 } /* if */
1763 if (value == NULL) {
1764 return STATUS_ACCESS_VIOLATION;
1765 } /* if */
1767 while (*str != '\0') {
1768 chCurrent = *str;
1769 if (chCurrent >= '0' && chCurrent <= '9') {
1770 digit = chCurrent - '0';
1771 } else if (chCurrent >= 'A' && chCurrent <= 'Z') {
1772 digit = chCurrent - 'A' + 10;
1773 } else if (chCurrent >= 'a' && chCurrent <= 'z') {
1774 digit = chCurrent - 'a' + 10;
1775 } else {
1776 digit = -1;
1777 } /* if */
1778 if (digit < 0 || digit >= base) {
1779 *value = bMinus ? -RunningTotal : RunningTotal;
1780 return STATUS_SUCCESS;
1781 } /* if */
1783 RunningTotal = RunningTotal * base + digit;
1784 str++;
1785 } /* while */
1787 *value = bMinus ? -RunningTotal : RunningTotal;
1788 return STATUS_SUCCESS;
1792 /**************************************************************************
1793 * RtlIntegerToChar (NTDLL.@)
1795 * Converts an unsigned integer to a character string.
1797 * RETURNS
1798 * Success: STATUS_SUCCESS. str contains the converted number
1799 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1800 * STATUS_BUFFER_OVERFLOW, if str would be larger than length.
1801 * STATUS_ACCESS_VIOLATION, if str is NULL.
1803 * NOTES
1804 * Instead of base 0 it uses 10 as base.
1805 * Writes at most length characters to the string str.
1806 * Str is '\0' terminated when length allows it.
1807 * When str fits exactly in length characters the '\0' is omitted.
1809 NTSTATUS WINAPI RtlIntegerToChar(
1810 ULONG value, /* [I] Value to be converted */
1811 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1812 ULONG length, /* [I] Length of the str buffer in bytes */
1813 PCHAR str) /* [O] Destination for the converted value */
1815 CHAR buffer[33];
1816 PCHAR pos;
1817 CHAR digit;
1818 ULONG len;
1820 if (base == 0) {
1821 base = 10;
1822 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1823 return STATUS_INVALID_PARAMETER;
1824 } /* if */
1826 pos = &buffer[32];
1827 *pos = '\0';
1829 do {
1830 pos--;
1831 digit = value % base;
1832 value = value / base;
1833 if (digit < 10) {
1834 *pos = '0' + digit;
1835 } else {
1836 *pos = 'A' + digit - 10;
1837 } /* if */
1838 } while (value != 0L);
1840 len = &buffer[32] - pos;
1841 if (len > length) {
1842 return STATUS_BUFFER_OVERFLOW;
1843 } else if (str == NULL) {
1844 return STATUS_ACCESS_VIOLATION;
1845 } else if (len == length) {
1846 memcpy(str, pos, len);
1847 } else {
1848 memcpy(str, pos, len + 1);
1849 } /* if */
1850 return STATUS_SUCCESS;
1854 /**************************************************************************
1855 * RtlUnicodeStringToInteger (NTDLL.@)
1857 * Converts a unicode string into its integer equivalent.
1859 * RETURNS
1860 * Success: STATUS_SUCCESS. value contains the converted number
1861 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1862 * STATUS_ACCESS_VIOLATION, if value is NULL.
1864 * NOTES
1865 * For base 0 it uses 10 as base and the string should be in the format
1866 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1867 * For other bases the string should be in the format
1868 * "{whitespace} [+|-] {digits}".
1869 * No check is made for value overflow, only the lower 32 bits are assigned.
1870 * If str is NULL it crashes, as the native function does.
1872 * DIFFERENCES
1873 * This function does not read garbage on string length 0 as the native
1874 * version does.
1876 NTSTATUS WINAPI RtlUnicodeStringToInteger(
1877 const UNICODE_STRING *str, /* [I] Unicode string to be converted */
1878 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1879 ULONG *value) /* [O] Destination for the converted value */
1881 LPWSTR lpwstr = str->Buffer;
1882 USHORT CharsRemaining = str->Length / sizeof(WCHAR);
1883 WCHAR wchCurrent;
1884 int digit;
1885 ULONG RunningTotal = 0;
1886 BOOL bMinus = FALSE;
1888 while (CharsRemaining >= 1 && *lpwstr <= ' ') {
1889 lpwstr++;
1890 CharsRemaining--;
1891 } /* while */
1893 if (CharsRemaining >= 1) {
1894 if (*lpwstr == '+') {
1895 lpwstr++;
1896 CharsRemaining--;
1897 } else if (*lpwstr == '-') {
1898 bMinus = TRUE;
1899 lpwstr++;
1900 CharsRemaining--;
1901 } /* if */
1902 } /* if */
1904 if (base == 0) {
1905 base = 10;
1906 if (CharsRemaining >= 2 && lpwstr[0] == '0') {
1907 if (lpwstr[1] == 'b') {
1908 lpwstr += 2;
1909 CharsRemaining -= 2;
1910 base = 2;
1911 } else if (lpwstr[1] == 'o') {
1912 lpwstr += 2;
1913 CharsRemaining -= 2;
1914 base = 8;
1915 } else if (lpwstr[1] == 'x') {
1916 lpwstr += 2;
1917 CharsRemaining -= 2;
1918 base = 16;
1919 } /* if */
1920 } /* if */
1921 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1922 return STATUS_INVALID_PARAMETER;
1923 } /* if */
1925 if (value == NULL) {
1926 return STATUS_ACCESS_VIOLATION;
1927 } /* if */
1929 while (CharsRemaining >= 1) {
1930 wchCurrent = *lpwstr;
1931 if (wchCurrent >= '0' && wchCurrent <= '9') {
1932 digit = wchCurrent - '0';
1933 } else if (wchCurrent >= 'A' && wchCurrent <= 'Z') {
1934 digit = wchCurrent - 'A' + 10;
1935 } else if (wchCurrent >= 'a' && wchCurrent <= 'z') {
1936 digit = wchCurrent - 'a' + 10;
1937 } else {
1938 digit = -1;
1939 } /* if */
1940 if (digit < 0 || digit >= base) {
1941 *value = bMinus ? -RunningTotal : RunningTotal;
1942 return STATUS_SUCCESS;
1943 } /* if */
1945 RunningTotal = RunningTotal * base + digit;
1946 lpwstr++;
1947 CharsRemaining--;
1948 } /* while */
1950 *value = bMinus ? -RunningTotal : RunningTotal;
1951 return STATUS_SUCCESS;
1955 /**************************************************************************
1956 * RtlIntegerToUnicodeString (NTDLL.@)
1958 * Converts an unsigned integer to a '\0' terminated unicode string.
1960 * RETURNS
1961 * Success: STATUS_SUCCESS. str contains the converted number
1962 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1963 * STATUS_BUFFER_OVERFLOW, if str is too small to hold the string
1964 * (with the '\0' termination). In this case str->Length
1965 * is set to the length, the string would have (which can
1966 * be larger than the MaximumLength).
1968 * NOTES
1969 * Instead of base 0 it uses 10 as base.
1970 * If str is NULL it crashes, as the native function does.
1972 * DIFFERENCES
1973 * Do not return STATUS_BUFFER_OVERFLOW when the string is long enough.
1974 * The native function does this when the string would be longer than 16
1975 * characters even when the string parameter is long enough.
1977 NTSTATUS WINAPI RtlIntegerToUnicodeString(
1978 ULONG value, /* [I] Value to be converted */
1979 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1980 UNICODE_STRING *str) /* [O] Destination for the converted value */
1982 WCHAR buffer[33];
1983 PWCHAR pos;
1984 WCHAR digit;
1986 if (base == 0) {
1987 base = 10;
1988 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1989 return STATUS_INVALID_PARAMETER;
1990 } /* if */
1992 pos = &buffer[32];
1993 *pos = '\0';
1995 do {
1996 pos--;
1997 digit = value % base;
1998 value = value / base;
1999 if (digit < 10) {
2000 *pos = '0' + digit;
2001 } else {
2002 *pos = 'A' + digit - 10;
2003 } /* if */
2004 } while (value != 0L);
2006 str->Length = (&buffer[32] - pos) * sizeof(WCHAR);
2007 if (str->Length >= str->MaximumLength) {
2008 return STATUS_BUFFER_OVERFLOW;
2009 } else {
2010 memcpy(str->Buffer, pos, str->Length + sizeof(WCHAR));
2011 } /* if */
2012 return STATUS_SUCCESS;
2016 /*************************************************************************
2017 * RtlGUIDFromString (NTDLL.@)
2019 * Convert a string representation of a GUID into a GUID.
2021 * PARAMS
2022 * str [I] String representation in the format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
2023 * guid [O] Destination for the converted GUID
2025 * RETURNS
2026 * Success: STATUS_SUCCESS. guid contains the converted value.
2027 * Failure: STATUS_INVALID_PARAMETER, if str is not in the expected format.
2029 * SEE ALSO
2030 * See RtlStringFromGUID.
2032 NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING str, GUID* guid)
2034 int i = 0;
2035 const WCHAR *lpszCLSID = str->Buffer;
2036 BYTE* lpOut = (BYTE*)guid;
2038 TRACE("(%s,%p)\n", debugstr_us(str), guid);
2040 /* Convert string: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
2041 * to memory: DWORD... WORD WORD BYTES............
2043 while (i <= 37)
2045 switch (i)
2047 case 0:
2048 if (*lpszCLSID != '{')
2049 return STATUS_INVALID_PARAMETER;
2050 break;
2052 case 9: case 14: case 19: case 24:
2053 if (*lpszCLSID != '-')
2054 return STATUS_INVALID_PARAMETER;
2055 break;
2057 case 37:
2058 if (*lpszCLSID != '}')
2059 return STATUS_INVALID_PARAMETER;
2060 break;
2062 default:
2064 WCHAR ch = *lpszCLSID, ch2 = lpszCLSID[1];
2065 unsigned char byte;
2067 /* Read two hex digits as a byte value */
2068 if (ch >= '0' && ch <= '9') ch = ch - '0';
2069 else if (ch >= 'a' && ch <= 'f') ch = ch - 'a' + 10;
2070 else if (ch >= 'A' && ch <= 'F') ch = ch - 'A' + 10;
2071 else return STATUS_INVALID_PARAMETER;
2073 if (ch2 >= '0' && ch2 <= '9') ch2 = ch2 - '0';
2074 else if (ch2 >= 'a' && ch2 <= 'f') ch2 = ch2 - 'a' + 10;
2075 else if (ch2 >= 'A' && ch2 <= 'F') ch2 = ch2 - 'A' + 10;
2076 else return STATUS_INVALID_PARAMETER;
2078 byte = ch << 4 | ch2;
2080 switch (i)
2082 #ifndef WORDS_BIGENDIAN
2083 /* For Big Endian machines, we store the data such that the
2084 * dword/word members can be read as DWORDS and WORDS correctly. */
2085 /* Dword */
2086 case 1: lpOut[3] = byte; break;
2087 case 3: lpOut[2] = byte; break;
2088 case 5: lpOut[1] = byte; break;
2089 case 7: lpOut[0] = byte; lpOut += 4; break;
2090 /* Word */
2091 case 10: case 15: lpOut[1] = byte; break;
2092 case 12: case 17: lpOut[0] = byte; lpOut += 2; break;
2093 #endif
2094 /* Byte */
2095 default: lpOut[0] = byte; lpOut++; break;
2097 lpszCLSID++; /* Skip 2nd character of byte */
2098 i++;
2101 lpszCLSID++;
2102 i++;
2105 return STATUS_SUCCESS;
2108 /*************************************************************************
2109 * RtlStringFromGUID (NTDLL.@)
2111 * Convert a GUID into a string representation of a GUID.
2113 * PARAMS
2114 * guid [I] GUID to convert
2115 * str [O] Destination for the converted string
2117 * RETURNS
2118 * Success: STATUS_SUCCESS. str contains the converted value.
2119 * Failure: STATUS_NO_MEMORY, if memory for str cannot be allocated.
2121 * SEE ALSO
2122 * See RtlGUIDFromString.
2124 NTSTATUS WINAPI RtlStringFromGUID(const GUID* guid, UNICODE_STRING *str)
2126 static const WCHAR szFormat[] = { '{','%','0','8','l','X','-',
2127 '%','0','4','X','-', '%','0','4','X','-','%','0','2','X','%','0','2','X',
2128 '-', '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
2129 '%','0','2','X','%','0','2','X','}','\0' };
2131 TRACE("(%p,%p)\n", guid, str);
2133 str->Length = GUID_STRING_LENGTH * sizeof(WCHAR);
2134 str->MaximumLength = str->Length + sizeof(WCHAR);
2135 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, str->MaximumLength);
2136 if (!str->Buffer)
2138 str->Length = str->MaximumLength = 0;
2139 return STATUS_NO_MEMORY;
2141 sprintfW(str->Buffer, szFormat, guid->Data1, guid->Data2, guid->Data3,
2142 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
2143 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
2145 return STATUS_SUCCESS;
2148 /******************************************************************************
2149 * RtlHashUnicodeString [NTDLL.@]
2151 NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING string, BOOLEAN case_insensitive, ULONG alg, ULONG *hash)
2153 unsigned int i;
2155 if (!string || !hash) return STATUS_INVALID_PARAMETER;
2157 switch (alg)
2159 case HASH_STRING_ALGORITHM_DEFAULT:
2160 case HASH_STRING_ALGORITHM_X65599:
2161 break;
2162 default:
2163 return STATUS_INVALID_PARAMETER;
2166 *hash = 0;
2167 for (i = 0; i < string->Length/sizeof(WCHAR); i++)
2168 *hash = *hash*65599 + (case_insensitive ? toupperW(string->Buffer[i]) : string->Buffer[i]);
2170 return STATUS_SUCCESS;