ntoskrnl.exe: Implement ExAcquireFastMutex and ExReleaseFastMutex.
[wine.git] / dlls / ntdll / rtlstr.c
blobe834ad244033354fc07be119f80173f875dc4b9e
1 /*
2 * Rtl string functions
4 * Copyright (C) 1996-1998 Marcus Meissner
5 * Copyright (C) 2000 Alexandre Julliard
6 * Copyright (C) 2003 Thomas Mertes
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winnt.h"
34 #include "winternl.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37 #include "ntdll_misc.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
41 #define GUID_STRING_LENGTH 38
43 UINT NlsAnsiCodePage = 0;
44 BYTE NlsMbCodePageTag = 0;
45 BYTE NlsMbOemCodePageTag = 0;
47 extern const union cptable cptable_20127; /* 7-bit ASCII */
49 static const union cptable *ansi_table = &cptable_20127;
50 static const union cptable *oem_table = &cptable_20127;
51 static const union cptable* unix_table; /* NULL if UTF8 */
54 /**************************************************************************
55 * __wine_init_codepages (NTDLL.@)
57 * Set the code page once kernel32 is loaded. Should be done differently.
59 void CDECL __wine_init_codepages( const union cptable *ansi, const union cptable *oem,
60 const union cptable *ucp)
62 ansi_table = ansi;
63 oem_table = oem;
64 unix_table = ucp;
65 NlsAnsiCodePage = ansi->info.codepage;
66 init_directories();
69 int ntdll_umbstowcs(DWORD flags, const char* src, int srclen, WCHAR* dst, int dstlen)
71 #ifdef __APPLE__
72 /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
73 if (!unix_table) flags |= MB_COMPOSITE;
74 #endif
75 return (unix_table) ?
76 wine_cp_mbstowcs( unix_table, flags, src, srclen, dst, dstlen ) :
77 wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
80 int ntdll_wcstoumbs(DWORD flags, const WCHAR* src, int srclen, char* dst, int dstlen,
81 const char* defchar, int *used )
83 if (unix_table)
84 return wine_cp_wcstombs( unix_table, flags, src, srclen, dst, dstlen, defchar, used );
85 if (used) *used = 0; /* all chars are valid for UTF-8 */
86 return wine_utf8_wcstombs( flags, src, srclen, dst, dstlen );
89 /**************************************************************************
90 * RtlInitAnsiString (NTDLL.@)
92 * Initializes a buffered ansi string.
94 * RETURNS
95 * Nothing.
97 * NOTES
98 * Assigns source to target->Buffer. The length of source is assigned to
99 * target->Length and target->MaximumLength. If source is NULL the length
100 * of source is assumed to be 0.
102 void WINAPI RtlInitAnsiString(
103 PANSI_STRING target, /* [I/O] Buffered ansi string to be initialized */
104 PCSZ source) /* [I] '\0' terminated string used to initialize target */
106 if ((target->Buffer = (PCHAR) source))
108 target->Length = strlen(source);
109 target->MaximumLength = target->Length + 1;
111 else target->Length = target->MaximumLength = 0;
114 /**************************************************************************
115 * RtlInitAnsiStringEx (NTDLL.@)
117 * Initializes a buffered ansi string.
119 * RETURNS
120 * An appropriate NTSTATUS value.
122 * NOTES
123 * Assigns source to target->Buffer. The length of source is assigned to
124 * target->Length and target->MaximumLength. If source is NULL the length
125 * of source is assumed to be 0.
127 NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING target, PCSZ source)
129 if (source)
131 unsigned int len = strlen(source);
132 if (len+1 > 0xffff)
133 return STATUS_NAME_TOO_LONG;
135 target->Buffer = (PCHAR) source;
136 target->Length = len;
137 target->MaximumLength = len + 1;
139 else
141 target->Buffer = NULL;
142 target->Length = 0;
143 target->MaximumLength = 0;
145 return STATUS_SUCCESS;
148 /**************************************************************************
149 * RtlInitString (NTDLL.@)
151 * Initializes a buffered string.
153 * RETURNS
154 * Nothing.
156 * NOTES
157 * Assigns source to target->Buffer. The length of source is assigned to
158 * target->Length and target->MaximumLength. If source is NULL the length
159 * of source is assumed to be 0.
161 void WINAPI RtlInitString(
162 PSTRING target, /* [I/O] Buffered string to be initialized */
163 PCSZ source) /* [I] '\0' terminated string used to initialize target */
165 RtlInitAnsiString( target, source );
169 /**************************************************************************
170 * RtlFreeAnsiString (NTDLL.@)
172 void WINAPI RtlFreeAnsiString( PSTRING str )
174 if (str->Buffer)
176 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
177 RtlZeroMemory( str, sizeof(*str) );
182 /**************************************************************************
183 * RtlFreeOemString (NTDLL.@)
185 void WINAPI RtlFreeOemString( PSTRING str )
187 RtlFreeAnsiString( str );
191 /**************************************************************************
192 * RtlCopyString (NTDLL.@)
194 void WINAPI RtlCopyString( STRING *dst, const STRING *src )
196 if (src)
198 unsigned int len = min( src->Length, dst->MaximumLength );
199 memcpy( dst->Buffer, src->Buffer, len );
200 dst->Length = len;
202 else dst->Length = 0;
206 /**************************************************************************
207 * RtlInitUnicodeString (NTDLL.@)
209 * Initializes a buffered unicode string.
211 * RETURNS
212 * Nothing.
214 * NOTES
215 * Assigns source to target->Buffer. The length of source is assigned to
216 * target->Length and target->MaximumLength. If source is NULL the length
217 * of source is assumed to be 0.
219 void WINAPI RtlInitUnicodeString(
220 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
221 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
223 if ((target->Buffer = (PWSTR) source))
225 unsigned int length = strlenW(source) * sizeof(WCHAR);
226 if (length > 0xfffc)
227 length = 0xfffc;
228 target->Length = length;
229 target->MaximumLength = target->Length + sizeof(WCHAR);
231 else target->Length = target->MaximumLength = 0;
235 /**************************************************************************
236 * RtlInitUnicodeStringEx (NTDLL.@)
238 * Initializes a buffered unicode string.
240 * RETURNS
241 * Success: STATUS_SUCCESS. target is initialized.
242 * Failure: STATUS_NAME_TOO_LONG, if the source string is larger than 65532 bytes.
244 * NOTES
245 * Assigns source to target->Buffer. The length of source is assigned to
246 * target->Length and target->MaximumLength. If source is NULL the length
247 * of source is assumed to be 0.
249 NTSTATUS WINAPI RtlInitUnicodeStringEx(
250 PUNICODE_STRING target, /* [I/O] Buffered unicode string to be initialized */
251 PCWSTR source) /* [I] '\0' terminated unicode string used to initialize target */
253 if (source != NULL) {
254 unsigned int len = strlenW(source) * sizeof(WCHAR);
256 if (len > 0xFFFC) {
257 return STATUS_NAME_TOO_LONG;
258 } else {
259 target->Length = len;
260 target->MaximumLength = len + sizeof(WCHAR);
261 target->Buffer = (PWSTR) source;
262 } /* if */
263 } else {
264 target->Length = 0;
265 target->MaximumLength = 0;
266 target->Buffer = NULL;
267 } /* if */
268 return STATUS_SUCCESS;
272 /**************************************************************************
273 * RtlCreateUnicodeString (NTDLL.@)
275 * Creates a UNICODE_STRING from a null-terminated Unicode string.
277 * RETURNS
278 * Success: TRUE
279 * Failure: FALSE
281 BOOLEAN WINAPI RtlCreateUnicodeString( PUNICODE_STRING target, LPCWSTR src )
283 int len = (strlenW(src) + 1) * sizeof(WCHAR);
284 if (!(target->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return FALSE;
285 memcpy( target->Buffer, src, len );
286 target->MaximumLength = len;
287 target->Length = len - sizeof(WCHAR);
288 return TRUE;
292 /**************************************************************************
293 * RtlCreateUnicodeStringFromAsciiz (NTDLL.@)
295 * Creates a UNICODE_STRING from a null-terminated Ascii string.
297 * RETURNS
298 * Success: TRUE
299 * Failure: FALSE
301 BOOLEAN WINAPI RtlCreateUnicodeStringFromAsciiz( PUNICODE_STRING target, LPCSTR src )
303 STRING ansi;
304 RtlInitAnsiString( &ansi, src );
305 return !RtlAnsiStringToUnicodeString( target, &ansi, TRUE );
309 /**************************************************************************
310 * RtlFreeUnicodeString (NTDLL.@)
312 * Frees a UNICODE_STRING created with RtlCreateUnicodeString() or
313 * RtlCreateUnicodeStringFromAsciiz().
315 * RETURNS
316 * nothing
318 void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str )
320 if (str->Buffer)
322 RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
323 RtlZeroMemory( str, sizeof(*str) );
328 /**************************************************************************
329 * RtlCopyUnicodeString (NTDLL.@)
331 * Copies from one UNICODE_STRING to another.
333 * RETURNS
334 * nothing
336 void WINAPI RtlCopyUnicodeString( UNICODE_STRING *dst, const UNICODE_STRING *src )
338 if (src)
340 unsigned int len = min( src->Length, dst->MaximumLength );
341 memcpy( dst->Buffer, src->Buffer, len );
342 dst->Length = len;
343 /* append terminating '\0' if enough space */
344 if (len < dst->MaximumLength) dst->Buffer[len / sizeof(WCHAR)] = 0;
346 else dst->Length = 0;
350 /**************************************************************************
351 * RtlDuplicateUnicodeString (NTDLL.@)
353 * Duplicates a unicode string.
355 * RETURNS
356 * Success: STATUS_SUCCESS. destination contains the duplicated unicode string.
357 * Failure: STATUS_INVALID_PARAMETER, if one of the parameters is illegal.
358 * STATUS_NO_MEMORY, if the allocation fails.
360 * NOTES
361 * For add_nul there are several possible values:
362 * 0 = destination will not be '\0' terminated,
363 * 1 = destination will be '\0' terminated,
364 * 3 = like 1 but for an empty source string produce '\0' terminated empty
365 * Buffer instead of assigning NULL to the Buffer.
366 * Other add_nul values are invalid.
368 NTSTATUS WINAPI RtlDuplicateUnicodeString(
369 int add_nul, /* [I] flag */
370 const UNICODE_STRING *source, /* [I] Unicode string to be duplicated */
371 UNICODE_STRING *destination) /* [O] destination for the duplicated unicode string */
373 if (source == NULL || destination == NULL ||
374 source->Length > source->MaximumLength ||
375 (source->Length == 0 && source->MaximumLength > 0 && source->Buffer == NULL) ||
376 add_nul == 2 || add_nul >= 4 || add_nul < 0) {
377 return STATUS_INVALID_PARAMETER;
378 } else {
379 if (source->Length == 0 && add_nul != 3) {
380 destination->Length = 0;
381 destination->MaximumLength = 0;
382 destination->Buffer = NULL;
383 } else {
384 unsigned int destination_max_len = source->Length;
386 if (add_nul) {
387 destination_max_len += sizeof(WCHAR);
388 } /* if */
389 destination->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, destination_max_len);
390 if (destination->Buffer == NULL) {
391 return STATUS_NO_MEMORY;
392 } else {
393 memcpy(destination->Buffer, source->Buffer, source->Length);
394 destination->Length = source->Length;
395 destination->MaximumLength = source->Length;
396 /* append terminating '\0' if enough space */
397 if (add_nul) {
398 destination->MaximumLength = destination_max_len;
399 destination->Buffer[destination->Length / sizeof(WCHAR)] = 0;
400 } /* if */
401 } /* if */
402 } /* if */
403 } /* if */
404 return STATUS_SUCCESS;
408 /**************************************************************************
409 * RtlEraseUnicodeString (NTDLL.@)
411 * Overwrites a UNICODE_STRING with zeros.
413 * RETURNS
414 * nothing
416 void WINAPI RtlEraseUnicodeString( UNICODE_STRING *str )
418 if (str->Buffer)
420 memset( str->Buffer, 0, str->MaximumLength );
421 str->Length = 0;
427 COMPARISON FUNCTIONS
431 /******************************************************************************
432 * RtlCompareString (NTDLL.@)
434 LONG WINAPI RtlCompareString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
436 unsigned int len;
437 LONG ret = 0;
438 LPCSTR p1, p2;
440 len = min(s1->Length, s2->Length);
441 p1 = s1->Buffer;
442 p2 = s2->Buffer;
444 if (CaseInsensitive)
446 while (!ret && len--) ret = RtlUpperChar(*p1++) - RtlUpperChar(*p2++);
448 else
450 while (!ret && len--) ret = *p1++ - *p2++;
452 if (!ret) ret = s1->Length - s2->Length;
453 return ret;
457 /******************************************************************************
458 * RtlCompareUnicodeStrings (NTDLL.@)
460 LONG WINAPI RtlCompareUnicodeStrings( const WCHAR *s1, SIZE_T len1, const WCHAR *s2, SIZE_T len2,
461 BOOLEAN case_insensitive )
463 LONG ret = 0;
464 SIZE_T len = min( len1, len2 );
466 if (case_insensitive)
468 while (!ret && len--) ret = toupperW(*s1++) - toupperW(*s2++);
470 else
472 while (!ret && len--) ret = *s1++ - *s2++;
474 if (!ret) ret = len1 - len2;
475 return ret;
479 /******************************************************************************
480 * RtlCompareUnicodeString (NTDLL.@)
482 LONG WINAPI RtlCompareUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
483 BOOLEAN CaseInsensitive )
485 return RtlCompareUnicodeStrings( s1->Buffer, s1->Length / sizeof(WCHAR),
486 s2->Buffer, s2->Length / sizeof(WCHAR), CaseInsensitive );
490 /**************************************************************************
491 * RtlEqualString (NTDLL.@)
493 * Determine if two strings are equal.
495 * PARAMS
496 * s1 [I] Source string
497 * s2 [I] String to compare to s1
498 * CaseInsensitive [I] TRUE = Case insensitive, FALSE = Case sensitive
500 * RETURNS
501 * Non-zero if s1 is equal to s2, 0 otherwise.
503 BOOLEAN WINAPI RtlEqualString( const STRING *s1, const STRING *s2, BOOLEAN CaseInsensitive )
505 if (s1->Length != s2->Length) return FALSE;
506 return !RtlCompareString( s1, s2, CaseInsensitive );
510 /**************************************************************************
511 * RtlEqualUnicodeString (NTDLL.@)
513 * Unicode version of RtlEqualString.
515 BOOLEAN WINAPI RtlEqualUnicodeString( const UNICODE_STRING *s1, const UNICODE_STRING *s2,
516 BOOLEAN CaseInsensitive )
518 if (s1->Length != s2->Length) return FALSE;
519 return !RtlCompareUnicodeString( s1, s2, CaseInsensitive );
523 /**************************************************************************
524 * RtlPrefixString (NTDLL.@)
526 * Determine if one string is a prefix of another.
528 * PARAMS
529 * s1 [I] Prefix to look for in s2
530 * s2 [I] String that may contain s1 as a prefix
531 * ignore_case [I] TRUE = Case insensitive, FALSE = Case sensitive
533 * RETURNS
534 * TRUE if s2 contains s1 as a prefix, FALSE otherwise.
536 BOOLEAN WINAPI RtlPrefixString( const STRING *s1, const STRING *s2, BOOLEAN ignore_case )
538 unsigned int i;
540 if (s1->Length > s2->Length) return FALSE;
541 if (ignore_case)
543 for (i = 0; i < s1->Length; i++)
544 if (RtlUpperChar(s1->Buffer[i]) != RtlUpperChar(s2->Buffer[i])) return FALSE;
546 else
548 for (i = 0; i < s1->Length; i++)
549 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
551 return TRUE;
555 /**************************************************************************
556 * RtlPrefixUnicodeString (NTDLL.@)
558 * Unicode version of RtlPrefixString.
560 BOOLEAN WINAPI RtlPrefixUnicodeString( const UNICODE_STRING *s1,
561 const UNICODE_STRING *s2,
562 BOOLEAN ignore_case )
564 unsigned int i;
566 if (s1->Length > s2->Length) return FALSE;
567 if (ignore_case)
569 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
570 if (toupperW(s1->Buffer[i]) != toupperW(s2->Buffer[i])) return FALSE;
572 else
574 for (i = 0; i < s1->Length / sizeof(WCHAR); i++)
575 if (s1->Buffer[i] != s2->Buffer[i]) return FALSE;
577 return TRUE;
581 /**************************************************************************
582 * RtlEqualComputerName (NTDLL.@)
584 * Determine if two computer names are the same.
586 * PARAMS
587 * left [I] First computer name
588 * right [I] Second computer name
590 * RETURNS
591 * 0 if the names are equal, non-zero otherwise.
593 * NOTES
594 * The comparison is case insensitive.
596 NTSTATUS WINAPI RtlEqualComputerName(const UNICODE_STRING *left,
597 const UNICODE_STRING *right)
599 NTSTATUS ret;
600 STRING upLeft, upRight;
602 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upLeft, left, TRUE )))
604 if (!(ret = RtlUpcaseUnicodeStringToOemString( &upRight, right, TRUE )))
606 ret = RtlEqualString( &upLeft, &upRight, FALSE );
607 RtlFreeOemString( &upRight );
609 RtlFreeOemString( &upLeft );
611 return ret;
615 /**************************************************************************
616 * RtlEqualDomainName (NTDLL.@)
618 * Determine if two domain names are the same.
620 * PARAMS
621 * left [I] First domain name
622 * right [I] Second domain name
624 * RETURNS
625 * 0 if the names are equal, non-zero otherwise.
627 * NOTES
628 * The comparison is case insensitive.
630 NTSTATUS WINAPI RtlEqualDomainName(const UNICODE_STRING *left,
631 const UNICODE_STRING *right)
633 return RtlEqualComputerName(left, right);
637 /**************************************************************************
638 * RtlAnsiCharToUnicodeChar (NTDLL.@)
640 * Converts the first ansi character to a unicode character.
642 * PARAMS
643 * ansi [I/O] Pointer to the ansi string.
645 * RETURNS
646 * Unicode representation of the first character in the ansi string.
648 * NOTES
649 * Upon successful completion, the char pointer ansi points to is
650 * incremented by the size of the character.
652 WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *ansi)
654 WCHAR str;
655 DWORD charSize = sizeof(CHAR);
657 if (wine_is_dbcs_leadbyte(ansi_table, **ansi))
658 charSize++;
660 RtlMultiByteToUnicodeN(&str, sizeof(WCHAR), NULL, *ansi, charSize);
661 *ansi += charSize;
663 return str;
667 COPY BETWEEN ANSI_STRING or UNICODE_STRING
668 there is no parameter checking, it just crashes
672 /**************************************************************************
673 * RtlAnsiStringToUnicodeString (NTDLL.@)
675 * Converts an ansi string to a unicode string.
677 * RETURNS
678 * Success: STATUS_SUCCESS. uni contains the converted string
679 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
680 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
681 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
683 * NOTES
684 * This function always writes a terminating '\0'.
686 NTSTATUS WINAPI RtlAnsiStringToUnicodeString(
687 PUNICODE_STRING uni, /* [I/O] Destination for the unicode string */
688 PCANSI_STRING ansi, /* [I] Ansi string to be converted */
689 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
691 DWORD total = RtlAnsiStringToUnicodeSize( ansi );
693 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
694 uni->Length = total - sizeof(WCHAR);
695 if (doalloc)
697 uni->MaximumLength = total;
698 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
699 return STATUS_NO_MEMORY;
701 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
703 RtlMultiByteToUnicodeN( uni->Buffer, uni->Length, NULL, ansi->Buffer, ansi->Length );
704 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
705 return STATUS_SUCCESS;
709 /**************************************************************************
710 * RtlOemStringToUnicodeString (NTDLL.@)
712 * Converts an oem string to a unicode string.
714 * RETURNS
715 * Success: STATUS_SUCCESS. uni contains the converted string
716 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
717 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
718 * STATUS_INVALID_PARAMETER_2, if the unicode string would be larger than 65535.
720 * NOTES
721 * This function always writes a terminating '\0'.
723 NTSTATUS WINAPI RtlOemStringToUnicodeString(
724 UNICODE_STRING *uni, /* [I/O] Destination for the unicode string */
725 const STRING *oem, /* [I] Oem string to be converted */
726 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for uni, FALSE=Use existing buffer */
728 DWORD total = RtlOemStringToUnicodeSize( oem );
730 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
731 uni->Length = total - sizeof(WCHAR);
732 if (doalloc)
734 uni->MaximumLength = total;
735 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total )))
736 return STATUS_NO_MEMORY;
738 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
740 RtlOemToUnicodeN( uni->Buffer, uni->Length, NULL, oem->Buffer, oem->Length );
741 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
742 return STATUS_SUCCESS;
746 /**************************************************************************
747 * RtlUnicodeStringToAnsiString (NTDLL.@)
749 * Converts a unicode string to an ansi string.
751 * RETURNS
752 * Success: STATUS_SUCCESS. ansi contains the converted string
753 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and ansi is too small.
754 * STATUS_NO_MEMORY, if doalloc is TRUE and the allocation fails.
756 * NOTES
757 * This function always writes a terminating '\0'.
758 * It performs a partial copy if ansi is too small.
760 NTSTATUS WINAPI RtlUnicodeStringToAnsiString(
761 STRING *ansi, /* [I/O] Destination for the ansi string */
762 const UNICODE_STRING *uni, /* [I] Unicode string to be converted */
763 BOOLEAN doalloc) /* [I] TRUE=Allocate new buffer for ansi, FALSE=Use existing buffer */
765 NTSTATUS ret = STATUS_SUCCESS;
766 DWORD len = RtlUnicodeStringToAnsiSize( uni );
768 ansi->Length = len - 1;
769 if (doalloc)
771 ansi->MaximumLength = len;
772 if (!(ansi->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
773 return STATUS_NO_MEMORY;
775 else if (ansi->MaximumLength < len)
777 if (!ansi->MaximumLength) return STATUS_BUFFER_OVERFLOW;
778 ansi->Length = ansi->MaximumLength - 1;
779 ret = STATUS_BUFFER_OVERFLOW;
782 RtlUnicodeToMultiByteN( ansi->Buffer, ansi->Length, NULL, uni->Buffer, uni->Length );
783 ansi->Buffer[ansi->Length] = 0;
784 return ret;
788 /**************************************************************************
789 * RtlUnicodeStringToOemString (NTDLL.@)
791 * Converts a Rtl Unicode string to an OEM string.
793 * PARAMS
794 * oem [O] Destination for OEM string
795 * uni [I] Source Unicode string
796 * doalloc [I] TRUE=Allocate new buffer for oem,FALSE=Use existing buffer
798 * RETURNS
799 * Success: STATUS_SUCCESS. oem contains the converted string
800 * Failure: STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and oem is too small.
801 * STATUS_NO_MEMORY, if doalloc is TRUE and allocation fails.
803 * NOTES
804 * If doalloc is TRUE, the length allocated is uni->Length + 1.
805 * This function always '\0' terminates the string returned.
807 NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
808 const UNICODE_STRING *uni,
809 BOOLEAN doalloc )
811 NTSTATUS ret = STATUS_SUCCESS;
812 DWORD len = RtlUnicodeStringToOemSize( uni );
814 oem->Length = len - 1;
815 if (doalloc)
817 oem->MaximumLength = len;
818 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
819 return STATUS_NO_MEMORY;
821 else if (oem->MaximumLength < len)
823 if (!oem->MaximumLength) return STATUS_BUFFER_OVERFLOW;
824 oem->Length = oem->MaximumLength - 1;
825 ret = STATUS_BUFFER_OVERFLOW;
828 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, uni->Buffer, uni->Length );
829 oem->Buffer[oem->Length] = 0;
830 return ret;
834 /**************************************************************************
835 * RtlMultiByteToUnicodeN (NTDLL.@)
837 * Converts a multi-byte string to a Unicode string.
839 * RETURNS
840 * NTSTATUS code
842 * NOTES
843 * Performs a partial copy if dst is too small.
845 NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
846 LPCSTR src, DWORD srclen )
849 int ret = wine_cp_mbstowcs( ansi_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
850 if (reslen)
851 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
852 return STATUS_SUCCESS;
856 /**************************************************************************
857 * RtlOemToUnicodeN (NTDLL.@)
859 * Converts a multi-byte string in the OEM code page to a Unicode string.
861 * RETURNS
862 * NTSTATUS code
864 NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
865 LPCSTR src, DWORD srclen )
867 int ret = wine_cp_mbstowcs( oem_table, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
868 if (reslen)
869 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
870 return STATUS_SUCCESS;
874 /**************************************************************************
875 * RtlUnicodeToMultiByteN (NTDLL.@)
877 * Converts a Unicode string to a multi-byte string in the ANSI code page.
879 * RETURNS
880 * NTSTATUS code
882 NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
883 LPCWSTR src, DWORD srclen )
885 int ret = wine_cp_wcstombs( ansi_table, 0, src, srclen / sizeof(WCHAR),
886 dst, dstlen, NULL, NULL );
887 if (reslen)
888 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
889 return STATUS_SUCCESS;
893 /**************************************************************************
894 * RtlUnicodeToOemN (NTDLL.@)
896 * Converts a Unicode string to a multi-byte string in the OEM code page.
898 * RETURNS
899 * NTSTATUS code
901 NTSTATUS WINAPI RtlUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
902 LPCWSTR src, DWORD srclen )
904 int ret = wine_cp_wcstombs( oem_table, 0, src, srclen / sizeof(WCHAR),
905 dst, dstlen, NULL, NULL );
906 if (reslen)
907 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
908 return STATUS_SUCCESS;
913 CASE CONVERSIONS
917 /**************************************************************************
918 * RtlUpperChar (NTDLL.@)
920 * Converts an Ascii character to uppercase.
922 * PARAMS
923 * ch [I] Character to convert
925 * RETURNS
926 * The uppercase character value.
928 * NOTES
929 * For the input characters from 'a' .. 'z' it returns 'A' .. 'Z'.
930 * All other input characters are returned unchanged. The locale and
931 * multibyte characters are not taken into account (as native DLL).
933 CHAR WINAPI RtlUpperChar( CHAR ch )
935 if (ch >= 'a' && ch <= 'z') {
936 return ch - 'a' + 'A';
937 } else {
938 return ch;
939 } /* if */
943 /**************************************************************************
944 * RtlUpperString (NTDLL.@)
946 * Converts an Ascii string to uppercase.
948 * PARAMS
949 * dst [O] Destination for converted string
950 * src [I] Source string to convert
952 * RETURNS
953 * Nothing.
955 * NOTES
956 * For the src characters from 'a' .. 'z' it assigns 'A' .. 'Z' to dst.
957 * All other src characters are copied unchanged to dst. The locale and
958 * multibyte characters are not taken into account (as native DLL).
959 * The number of character copied is the minimum of src->Length and
960 * the dst->MaximumLength.
962 void WINAPI RtlUpperString( STRING *dst, const STRING *src )
964 unsigned int i, len = min(src->Length, dst->MaximumLength);
966 for (i = 0; i < len; i++) dst->Buffer[i] = RtlUpperChar(src->Buffer[i]);
967 dst->Length = len;
971 /**************************************************************************
972 * RtlUpcaseUnicodeChar (NTDLL.@)
974 * Converts a Unicode character to uppercase.
976 * PARAMS
977 * wch [I] Character to convert
979 * RETURNS
980 * The uppercase character value.
982 WCHAR WINAPI RtlUpcaseUnicodeChar( WCHAR wch )
984 return toupperW(wch);
988 /**************************************************************************
989 * RtlDowncaseUnicodeChar (NTDLL.@)
991 * Converts a Unicode character to lowercase.
993 * PARAMS
994 * wch [I] Character to convert
996 * RETURNS
997 * The lowercase character value.
999 WCHAR WINAPI RtlDowncaseUnicodeChar(WCHAR wch)
1001 return tolowerW(wch);
1005 /**************************************************************************
1006 * RtlUpcaseUnicodeString (NTDLL.@)
1008 * Converts a Unicode string to uppercase.
1010 * PARAMS
1011 * dest [O] Destination for converted string
1012 * src [I] Source string to convert
1013 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1015 * RETURNS
1016 * Success: STATUS_SUCCESS. dest contains the converted string.
1017 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1018 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1020 * NOTES
1021 * dest is never '\0' terminated because it may be equal to src, and src
1022 * might not be '\0' terminated. dest->Length is only set upon success.
1024 NTSTATUS WINAPI RtlUpcaseUnicodeString( UNICODE_STRING *dest,
1025 const UNICODE_STRING *src,
1026 BOOLEAN doalloc)
1028 DWORD i, len = src->Length;
1030 if (doalloc)
1032 dest->MaximumLength = len;
1033 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1034 return STATUS_NO_MEMORY;
1036 else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
1038 for (i = 0; i < len/sizeof(WCHAR); i++) dest->Buffer[i] = toupperW(src->Buffer[i]);
1039 dest->Length = len;
1040 return STATUS_SUCCESS;
1044 /**************************************************************************
1045 * RtlDowncaseUnicodeString (NTDLL.@)
1047 * Converts a Unicode string to lowercase.
1049 * PARAMS
1050 * dest [O] Destination for converted string
1051 * src [I] Source string to convert
1052 * doalloc [I] TRUE=Allocate a buffer for dest if it doesn't have one
1054 * RETURNS
1055 * Success: STATUS_SUCCESS. dest contains the converted string.
1056 * Failure: STATUS_NO_MEMORY, if doalloc is TRUE and memory allocation fails, or
1057 * STATUS_BUFFER_OVERFLOW, if doalloc is FALSE and dest is too small.
1059 * NOTES
1060 * dest is never '\0' terminated because it may be equal to src, and src
1061 * might not be '\0' terminated. dest->Length is only set upon success.
1063 NTSTATUS WINAPI RtlDowncaseUnicodeString(
1064 UNICODE_STRING *dest,
1065 const UNICODE_STRING *src,
1066 BOOLEAN doalloc)
1068 DWORD i;
1069 DWORD len = src->Length;
1071 if (doalloc) {
1072 dest->MaximumLength = len;
1073 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) {
1074 return STATUS_NO_MEMORY;
1075 } /* if */
1076 } else if (len > dest->MaximumLength) {
1077 return STATUS_BUFFER_OVERFLOW;
1078 } /* if */
1080 for (i = 0; i < len/sizeof(WCHAR); i++) {
1081 dest->Buffer[i] = tolowerW(src->Buffer[i]);
1082 } /* for */
1083 dest->Length = len;
1084 return STATUS_SUCCESS;
1088 /**************************************************************************
1089 * RtlUpcaseUnicodeStringToAnsiString (NTDLL.@)
1091 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1093 * RETURNS
1094 * NTSTATUS code
1096 * NOTES
1097 * writes terminating 0
1099 NTSTATUS WINAPI RtlUpcaseUnicodeStringToAnsiString( STRING *dst,
1100 const UNICODE_STRING *src,
1101 BOOLEAN doalloc )
1103 NTSTATUS ret;
1104 UNICODE_STRING upcase;
1106 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1108 ret = RtlUnicodeStringToAnsiString( dst, &upcase, doalloc );
1109 RtlFreeUnicodeString( &upcase );
1111 return ret;
1115 /**************************************************************************
1116 * RtlUpcaseUnicodeStringToOemString (NTDLL.@)
1118 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1119 * stored in STRING format.
1121 * RETURNS
1122 * NTSTATUS code
1124 * NOTES
1125 * writes terminating 0
1127 NTSTATUS WINAPI RtlUpcaseUnicodeStringToOemString( STRING *dst,
1128 const UNICODE_STRING *src,
1129 BOOLEAN doalloc )
1131 NTSTATUS ret;
1132 UNICODE_STRING upcase;
1134 if (!(ret = RtlUpcaseUnicodeString( &upcase, src, TRUE )))
1136 ret = RtlUnicodeStringToOemString( dst, &upcase, doalloc );
1137 RtlFreeUnicodeString( &upcase );
1139 return ret;
1143 /**************************************************************************
1144 * RtlUpcaseUnicodeStringToCountedOemString (NTDLL.@)
1146 * Converts a UNICODE_STRING to the equivalent OEM upper-case representation
1147 * stored in STRING format.
1149 * RETURNS
1150 * NTSTATUS code
1152 * NOTES
1153 * Same as RtlUpcaseUnicodeStringToOemString but doesn't write terminating null
1155 NTSTATUS WINAPI RtlUpcaseUnicodeStringToCountedOemString( STRING *oem,
1156 const UNICODE_STRING *uni,
1157 BOOLEAN doalloc )
1159 NTSTATUS ret;
1160 UNICODE_STRING upcase;
1161 WCHAR tmp[32];
1163 upcase.Buffer = tmp;
1164 upcase.MaximumLength = sizeof(tmp);
1165 ret = RtlUpcaseUnicodeString( &upcase, uni, FALSE );
1166 if (ret == STATUS_BUFFER_OVERFLOW) ret = RtlUpcaseUnicodeString( &upcase, uni, TRUE );
1168 if (!ret)
1170 DWORD len = RtlUnicodeStringToOemSize( &upcase ) - 1;
1171 oem->Length = len;
1172 if (doalloc)
1174 oem->MaximumLength = len;
1175 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len )))
1177 ret = STATUS_NO_MEMORY;
1178 goto done;
1181 else if (oem->MaximumLength < len)
1183 ret = STATUS_BUFFER_OVERFLOW;
1184 oem->Length = oem->MaximumLength;
1185 if (!oem->MaximumLength) goto done;
1187 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, upcase.Buffer, upcase.Length );
1188 done:
1189 if (upcase.Buffer != tmp) RtlFreeUnicodeString( &upcase );
1191 return ret;
1195 /**************************************************************************
1196 * RtlUpcaseUnicodeToMultiByteN (NTDLL.@)
1198 * Converts a Unicode string to the equivalent ANSI upper-case representation.
1200 * RETURNS
1201 * NTSTATUS code
1203 NTSTATUS WINAPI RtlUpcaseUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1204 LPCWSTR src, DWORD srclen )
1206 NTSTATUS ret;
1207 LPWSTR upcase;
1208 DWORD i;
1210 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1211 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1212 ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen );
1213 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1214 return ret;
1218 /**************************************************************************
1219 * RtlUpcaseUnicodeToOemN (NTDLL.@)
1221 * Converts a Unicode string to the equivalent OEM upper-case representation.
1223 * RETURNS
1224 * NTSTATUS code
1226 NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
1227 LPCWSTR src, DWORD srclen )
1229 NTSTATUS ret;
1230 LPWSTR upcase;
1231 DWORD i;
1233 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
1234 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
1235 ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen );
1236 RtlFreeHeap( GetProcessHeap(), 0, upcase );
1237 return ret;
1242 STRING SIZE
1246 /**************************************************************************
1247 * RtlOemStringToUnicodeSize (NTDLL.@)
1248 * RtlxOemStringToUnicodeSize (NTDLL.@)
1250 * Calculate the size in bytes necessary for the Unicode conversion of str,
1251 * including the terminating '\0'.
1253 * PARAMS
1254 * str [I] String to calculate the size of
1256 * RETURNS
1257 * The calculated size.
1259 UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str )
1261 int ret = wine_cp_mbstowcs( oem_table, 0, str->Buffer, str->Length, NULL, 0 );
1262 return (ret + 1) * sizeof(WCHAR);
1266 /**************************************************************************
1267 * RtlAnsiStringToUnicodeSize (NTDLL.@)
1268 * RtlxAnsiStringToUnicodeSize (NTDLL.@)
1270 * Calculate the size in bytes necessary for the Unicode conversion of str,
1271 * including the terminating '\0'.
1273 * PARAMS
1274 * str [I] String to calculate the size of
1276 * RETURNS
1277 * The calculated size.
1279 DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str )
1281 DWORD ret;
1282 RtlMultiByteToUnicodeSize( &ret, str->Buffer, str->Length );
1283 return ret + sizeof(WCHAR);
1287 /**************************************************************************
1288 * RtlMultiByteToUnicodeSize (NTDLL.@)
1290 * Compute the size in bytes necessary for the Unicode conversion of str,
1291 * without the terminating '\0'.
1293 * PARAMS
1294 * size [O] Destination for size
1295 * str [I] String to calculate the size of
1296 * len [I] Length of str
1298 * RETURNS
1299 * STATUS_SUCCESS.
1301 NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
1303 *size = wine_cp_mbstowcs( ansi_table, 0, str, len, NULL, 0 ) * sizeof(WCHAR);
1304 return STATUS_SUCCESS;
1308 /**************************************************************************
1309 * RtlUnicodeToMultiByteSize (NTDLL.@)
1311 * Calculate the size in bytes necessary for the multibyte conversion of str,
1312 * without the terminating '\0'.
1314 * PARAMS
1315 * size [O] Destination for size
1316 * str [I] String to calculate the size of
1317 * len [I] Length of str
1319 * RETURNS
1320 * STATUS_SUCCESS.
1322 NTSTATUS WINAPI RtlUnicodeToMultiByteSize( PULONG size, LPCWSTR str, ULONG len )
1324 *size = wine_cp_wcstombs( ansi_table, 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL );
1325 return STATUS_SUCCESS;
1329 /**************************************************************************
1330 * RtlUnicodeStringToAnsiSize (NTDLL.@)
1331 * RtlxUnicodeStringToAnsiSize (NTDLL.@)
1333 * Calculate the size in bytes necessary for the Ansi conversion of str,
1334 * including the terminating '\0'.
1336 * PARAMS
1337 * str [I] String to calculate the size of
1339 * RETURNS
1340 * The calculated size.
1342 DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
1344 DWORD ret;
1345 RtlUnicodeToMultiByteSize( &ret, str->Buffer, str->Length );
1346 return ret + 1;
1350 /**************************************************************************
1351 * RtlUnicodeStringToOemSize (NTDLL.@)
1352 * RtlxUnicodeStringToOemSize (NTDLL.@)
1354 * Calculate the size in bytes necessary for the OEM conversion of str,
1355 * including the terminating '\0'.
1357 * PARAMS
1358 * str [I] String to calculate the size of
1360 * RETURNS
1361 * The calculated size.
1363 DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str )
1365 return wine_cp_wcstombs( oem_table, 0, str->Buffer, str->Length / sizeof(WCHAR),
1366 NULL, 0, NULL, NULL ) + 1;
1370 /**************************************************************************
1371 * RtlAppendAsciizToString (NTDLL.@)
1373 * Concatenates a buffered character string and a '\0' terminated character
1374 * string
1376 * RETURNS
1377 * Success: STATUS_SUCCESS. src is appended to dest.
1378 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1379 * to hold the concatenated string.
1381 * NOTES
1382 * if src is NULL dest is unchanged.
1383 * dest is never '\0' terminated.
1385 NTSTATUS WINAPI RtlAppendAsciizToString(
1386 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1387 LPCSTR src) /* [I] '\0' terminated character string to be concatenated */
1389 if (src != NULL) {
1390 unsigned int src_len = strlen(src);
1391 unsigned int dest_len = src_len + dest->Length;
1393 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1394 memcpy(dest->Buffer + dest->Length, src, src_len);
1395 dest->Length = dest_len;
1396 } /* if */
1397 return STATUS_SUCCESS;
1401 /**************************************************************************
1402 * RtlAppendStringToString (NTDLL.@)
1404 * Concatenates two buffered character strings
1406 * RETURNS
1407 * Success: STATUS_SUCCESS. src is appended to dest.
1408 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1409 * to hold the concatenated string.
1411 * NOTES
1412 * if src->length is zero dest is unchanged.
1413 * dest is never '\0' terminated.
1415 NTSTATUS WINAPI RtlAppendStringToString(
1416 STRING *dest, /* [I/O] Buffered character string to which src is concatenated */
1417 const STRING *src) /* [I] Buffered character string to be concatenated */
1419 if (src->Length != 0) {
1420 unsigned int dest_len = src->Length + dest->Length;
1422 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1423 memcpy(dest->Buffer + dest->Length, src->Buffer, src->Length);
1424 dest->Length = dest_len;
1425 } /* if */
1426 return STATUS_SUCCESS;
1430 /**************************************************************************
1431 * RtlAppendUnicodeToString (NTDLL.@)
1433 * Concatenates a buffered unicode string and a '\0' terminated unicode
1434 * string
1436 * RETURNS
1437 * Success: STATUS_SUCCESS. src is appended to dest.
1438 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1439 * to hold the concatenated string.
1441 * NOTES
1442 * if src is NULL dest is unchanged.
1443 * dest is '\0' terminated when the MaximumLength allows it.
1444 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1446 * DIFFERENCES
1447 * Does not write in the src->Buffer beyond MaximumLength when
1448 * MaximumLength is odd as the native function does.
1450 NTSTATUS WINAPI RtlAppendUnicodeToString(
1451 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1452 LPCWSTR src) /* [I] '\0' terminated unicode string to be concatenated */
1454 if (src != NULL) {
1455 unsigned int src_len = strlenW(src) * sizeof(WCHAR);
1456 unsigned int dest_len = src_len + dest->Length;
1458 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1459 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src, src_len);
1460 dest->Length = dest_len;
1461 /* append terminating '\0' if enough space */
1462 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1463 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1464 } /* if */
1465 } /* if */
1466 return STATUS_SUCCESS;
1470 /**************************************************************************
1471 * RtlAppendUnicodeStringToString (NTDLL.@)
1473 * Concatenates two buffered unicode strings
1475 * RETURNS
1476 * Success: STATUS_SUCCESS. src is appended to dest.
1477 * Failure: STATUS_BUFFER_TOO_SMALL, if the buffer of dest is too small
1478 * to hold the concatenated string.
1480 * NOTES
1481 * if src->length is zero dest is unchanged.
1482 * dest is '\0' terminated when the MaximumLength allows it.
1483 * When dest fits exactly in MaximumLength characters the '\0' is omitted.
1485 * DIFFERENCES
1486 * Does not write in the src->Buffer beyond MaximumLength when
1487 * MaximumLength is odd as the native function does.
1489 NTSTATUS WINAPI RtlAppendUnicodeStringToString(
1490 UNICODE_STRING *dest, /* [I/O] Buffered unicode string to which src is concatenated */
1491 const UNICODE_STRING *src) /* [I] Buffered unicode string to be concatenated */
1493 if (src->Length != 0) {
1494 unsigned int dest_len = src->Length + dest->Length;
1496 if (dest_len > dest->MaximumLength) return STATUS_BUFFER_TOO_SMALL;
1497 memcpy(dest->Buffer + dest->Length/sizeof(WCHAR), src->Buffer, src->Length);
1498 dest->Length = dest_len;
1499 /* append terminating '\0' if enough space */
1500 if (dest_len + sizeof(WCHAR) <= dest->MaximumLength) {
1501 dest->Buffer[dest_len / sizeof(WCHAR)] = 0;
1502 } /* if */
1503 } /* if */
1504 return STATUS_SUCCESS;
1508 /**************************************************************************
1509 * RtlFindCharInUnicodeString (NTDLL.@)
1511 * Searches for one of several unicode characters in a unicode string.
1513 * RETURNS
1514 * Success: STATUS_SUCCESS. pos contains the position after the character found.
1515 * Failure: STATUS_NOT_FOUND, if none of the search_chars are in main_str.
1517 NTSTATUS WINAPI RtlFindCharInUnicodeString(
1518 int flags, /* [I] Flags */
1519 const UNICODE_STRING *main_str, /* [I] Unicode string in which one or more characters are searched */
1520 const UNICODE_STRING *search_chars, /* [I] Unicode string which contains the characters to search for */
1521 USHORT *pos) /* [O] Position of the first character found + 2 */
1523 unsigned int main_idx, search_idx;
1525 switch (flags) {
1526 case 0:
1527 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1528 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1529 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1530 *pos = (main_idx + 1) * sizeof(WCHAR);
1531 return STATUS_SUCCESS;
1535 *pos = 0;
1536 return STATUS_NOT_FOUND;
1537 case 1:
1538 main_idx = main_str->Length / sizeof(WCHAR);
1539 while (main_idx-- > 0) {
1540 for (search_idx = 0; search_idx < search_chars->Length / sizeof(WCHAR); search_idx++) {
1541 if (main_str->Buffer[main_idx] == search_chars->Buffer[search_idx]) {
1542 *pos = main_idx * sizeof(WCHAR);
1543 return STATUS_SUCCESS;
1547 *pos = 0;
1548 return STATUS_NOT_FOUND;
1549 case 2:
1550 for (main_idx = 0; main_idx < main_str->Length / sizeof(WCHAR); main_idx++) {
1551 search_idx = 0;
1552 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1553 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1554 search_idx++;
1556 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1557 *pos = (main_idx + 1) * sizeof(WCHAR);
1558 return STATUS_SUCCESS;
1561 *pos = 0;
1562 return STATUS_NOT_FOUND;
1563 case 3:
1564 main_idx = main_str->Length / sizeof(WCHAR);
1565 while (main_idx-- > 0) {
1566 search_idx = 0;
1567 while (search_idx < search_chars->Length / sizeof(WCHAR) &&
1568 main_str->Buffer[main_idx] != search_chars->Buffer[search_idx]) {
1569 search_idx++;
1571 if (search_idx >= search_chars->Length / sizeof(WCHAR)) {
1572 *pos = main_idx * sizeof(WCHAR);
1573 return STATUS_SUCCESS;
1576 *pos = 0;
1577 return STATUS_NOT_FOUND;
1578 } /* switch */
1579 return STATUS_NOT_FOUND;
1584 MISC
1587 /**************************************************************************
1588 * RtlIsTextUnicode (NTDLL.@)
1590 * Attempt to guess whether a text buffer is Unicode.
1592 * PARAMS
1593 * buf [I] Text buffer to test
1594 * len [I] Length of buf
1595 * pf [O] Destination for test results
1597 * RETURNS
1598 * TRUE if the buffer is likely Unicode, FALSE otherwise.
1600 * FIXME
1601 * Should implement more tests.
1603 BOOLEAN WINAPI RtlIsTextUnicode( LPCVOID buf, INT len, INT *pf )
1605 static const WCHAR std_control_chars[] = {'\r','\n','\t',' ',0x3000,0};
1606 static const WCHAR byterev_control_chars[] = {0x0d00,0x0a00,0x0900,0x2000,0};
1607 const WCHAR *s = buf;
1608 int i;
1609 unsigned int flags = ~0U, out_flags = 0;
1611 if (len < sizeof(WCHAR))
1613 /* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
1614 if (pf) *pf = 0;
1615 return FALSE;
1617 if (pf)
1618 flags = *pf;
1620 * Apply various tests to the text string. According to the
1621 * docs, each test "passed" sets the corresponding flag in
1622 * the output flags. But some of the tests are mutually
1623 * exclusive, so I don't see how you could pass all tests ...
1626 /* Check for an odd length ... pass if even. */
1627 if (len & 1) out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
1629 if (((const char *)buf)[len - 1] == 0)
1630 len--; /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES */
1632 len /= sizeof(WCHAR);
1633 /* Windows only checks the first 256 characters */
1634 if (len > 256) len = 256;
1636 /* Check for the special byte order unicode marks. */
1637 if (*s == 0xFEFF) out_flags |= IS_TEXT_UNICODE_SIGNATURE;
1638 if (*s == 0xFFFE) out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
1640 /* apply some statistical analysis */
1641 if (flags & IS_TEXT_UNICODE_STATISTICS)
1643 int stats = 0;
1644 /* FIXME: checks only for ASCII characters in the unicode stream */
1645 for (i = 0; i < len; i++)
1647 if (s[i] <= 255) stats++;
1649 if (stats > len / 2)
1650 out_flags |= IS_TEXT_UNICODE_STATISTICS;
1653 /* Check for unicode NULL chars */
1654 if (flags & IS_TEXT_UNICODE_NULL_BYTES)
1656 for (i = 0; i < len; i++)
1658 if (!(s[i] & 0xff) || !(s[i] >> 8))
1660 out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
1661 break;
1666 if (flags & IS_TEXT_UNICODE_CONTROLS)
1668 for (i = 0; i < len; i++)
1670 if (strchrW(std_control_chars, s[i]))
1672 out_flags |= IS_TEXT_UNICODE_CONTROLS;
1673 break;
1678 if (flags & IS_TEXT_UNICODE_REVERSE_CONTROLS)
1680 for (i = 0; i < len; i++)
1682 if (strchrW(byterev_control_chars, s[i]))
1684 out_flags |= IS_TEXT_UNICODE_REVERSE_CONTROLS;
1685 break;
1690 if (pf)
1692 out_flags &= *pf;
1693 *pf = out_flags;
1695 /* check for flags that indicate it's definitely not valid Unicode */
1696 if (out_flags & (IS_TEXT_UNICODE_REVERSE_MASK | IS_TEXT_UNICODE_NOT_UNICODE_MASK)) return FALSE;
1697 /* now check for invalid ASCII, and assume Unicode if so */
1698 if (out_flags & IS_TEXT_UNICODE_NOT_ASCII_MASK) return TRUE;
1699 /* now check for Unicode flags */
1700 if (out_flags & IS_TEXT_UNICODE_UNICODE_MASK) return TRUE;
1701 /* no flags set */
1702 return FALSE;
1706 /**************************************************************************
1707 * RtlCharToInteger (NTDLL.@)
1709 * Converts a character string into its integer equivalent.
1711 * RETURNS
1712 * Success: STATUS_SUCCESS. value contains the converted number
1713 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1714 * STATUS_ACCESS_VIOLATION, if value is NULL.
1716 * NOTES
1717 * For base 0 it uses 10 as base and the string should be in the format
1718 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1719 * For other bases the string should be in the format
1720 * "{whitespace} [+|-] {digits}".
1721 * No check is made for value overflow, only the lower 32 bits are assigned.
1722 * If str is NULL it crashes, as the native function does.
1724 * DIFFERENCES
1725 * This function does not read garbage behind '\0' as the native version does.
1727 NTSTATUS WINAPI RtlCharToInteger(
1728 PCSZ str, /* [I] '\0' terminated single-byte string containing a number */
1729 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1730 ULONG *value) /* [O] Destination for the converted value */
1732 CHAR chCurrent;
1733 int digit;
1734 ULONG RunningTotal = 0;
1735 BOOL bMinus = FALSE;
1737 while (*str != '\0' && *str <= ' ') {
1738 str++;
1739 } /* while */
1741 if (*str == '+') {
1742 str++;
1743 } else if (*str == '-') {
1744 bMinus = TRUE;
1745 str++;
1746 } /* if */
1748 if (base == 0) {
1749 base = 10;
1750 if (str[0] == '0') {
1751 if (str[1] == 'b') {
1752 str += 2;
1753 base = 2;
1754 } else if (str[1] == 'o') {
1755 str += 2;
1756 base = 8;
1757 } else if (str[1] == 'x') {
1758 str += 2;
1759 base = 16;
1760 } /* if */
1761 } /* if */
1762 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1763 return STATUS_INVALID_PARAMETER;
1764 } /* if */
1766 if (value == NULL) {
1767 return STATUS_ACCESS_VIOLATION;
1768 } /* if */
1770 while (*str != '\0') {
1771 chCurrent = *str;
1772 if (chCurrent >= '0' && chCurrent <= '9') {
1773 digit = chCurrent - '0';
1774 } else if (chCurrent >= 'A' && chCurrent <= 'Z') {
1775 digit = chCurrent - 'A' + 10;
1776 } else if (chCurrent >= 'a' && chCurrent <= 'z') {
1777 digit = chCurrent - 'a' + 10;
1778 } else {
1779 digit = -1;
1780 } /* if */
1781 if (digit < 0 || digit >= base) {
1782 *value = bMinus ? -RunningTotal : RunningTotal;
1783 return STATUS_SUCCESS;
1784 } /* if */
1786 RunningTotal = RunningTotal * base + digit;
1787 str++;
1788 } /* while */
1790 *value = bMinus ? -RunningTotal : RunningTotal;
1791 return STATUS_SUCCESS;
1795 /**************************************************************************
1796 * RtlIntegerToChar (NTDLL.@)
1798 * Converts an unsigned integer to a character string.
1800 * RETURNS
1801 * Success: STATUS_SUCCESS. str contains the converted number
1802 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1803 * STATUS_BUFFER_OVERFLOW, if str would be larger than length.
1804 * STATUS_ACCESS_VIOLATION, if str is NULL.
1806 * NOTES
1807 * Instead of base 0 it uses 10 as base.
1808 * Writes at most length characters to the string str.
1809 * Str is '\0' terminated when length allows it.
1810 * When str fits exactly in length characters the '\0' is omitted.
1812 NTSTATUS WINAPI RtlIntegerToChar(
1813 ULONG value, /* [I] Value to be converted */
1814 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1815 ULONG length, /* [I] Length of the str buffer in bytes */
1816 PCHAR str) /* [O] Destination for the converted value */
1818 CHAR buffer[33];
1819 PCHAR pos;
1820 CHAR digit;
1821 ULONG len;
1823 if (base == 0) {
1824 base = 10;
1825 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1826 return STATUS_INVALID_PARAMETER;
1827 } /* if */
1829 pos = &buffer[32];
1830 *pos = '\0';
1832 do {
1833 pos--;
1834 digit = value % base;
1835 value = value / base;
1836 if (digit < 10) {
1837 *pos = '0' + digit;
1838 } else {
1839 *pos = 'A' + digit - 10;
1840 } /* if */
1841 } while (value != 0L);
1843 len = &buffer[32] - pos;
1844 if (len > length) {
1845 return STATUS_BUFFER_OVERFLOW;
1846 } else if (str == NULL) {
1847 return STATUS_ACCESS_VIOLATION;
1848 } else if (len == length) {
1849 memcpy(str, pos, len);
1850 } else {
1851 memcpy(str, pos, len + 1);
1852 } /* if */
1853 return STATUS_SUCCESS;
1857 /**************************************************************************
1858 * RtlUnicodeStringToInteger (NTDLL.@)
1860 * Converts a unicode string into its integer equivalent.
1862 * RETURNS
1863 * Success: STATUS_SUCCESS. value contains the converted number
1864 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1865 * STATUS_ACCESS_VIOLATION, if value is NULL.
1867 * NOTES
1868 * For base 0 it uses 10 as base and the string should be in the format
1869 * "{whitespace} [+|-] [0[x|o|b]] {digits}".
1870 * For other bases the string should be in the format
1871 * "{whitespace} [+|-] {digits}".
1872 * No check is made for value overflow, only the lower 32 bits are assigned.
1873 * If str is NULL it crashes, as the native function does.
1875 * DIFFERENCES
1876 * This function does not read garbage on string length 0 as the native
1877 * version does.
1879 NTSTATUS WINAPI RtlUnicodeStringToInteger(
1880 const UNICODE_STRING *str, /* [I] Unicode string to be converted */
1881 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1882 ULONG *value) /* [O] Destination for the converted value */
1884 LPWSTR lpwstr = str->Buffer;
1885 USHORT CharsRemaining = str->Length / sizeof(WCHAR);
1886 WCHAR wchCurrent;
1887 int digit;
1888 ULONG RunningTotal = 0;
1889 BOOL bMinus = FALSE;
1891 while (CharsRemaining >= 1 && *lpwstr <= ' ') {
1892 lpwstr++;
1893 CharsRemaining--;
1894 } /* while */
1896 if (CharsRemaining >= 1) {
1897 if (*lpwstr == '+') {
1898 lpwstr++;
1899 CharsRemaining--;
1900 } else if (*lpwstr == '-') {
1901 bMinus = TRUE;
1902 lpwstr++;
1903 CharsRemaining--;
1904 } /* if */
1905 } /* if */
1907 if (base == 0) {
1908 base = 10;
1909 if (CharsRemaining >= 2 && lpwstr[0] == '0') {
1910 if (lpwstr[1] == 'b') {
1911 lpwstr += 2;
1912 CharsRemaining -= 2;
1913 base = 2;
1914 } else if (lpwstr[1] == 'o') {
1915 lpwstr += 2;
1916 CharsRemaining -= 2;
1917 base = 8;
1918 } else if (lpwstr[1] == 'x') {
1919 lpwstr += 2;
1920 CharsRemaining -= 2;
1921 base = 16;
1922 } /* if */
1923 } /* if */
1924 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1925 return STATUS_INVALID_PARAMETER;
1926 } /* if */
1928 if (value == NULL) {
1929 return STATUS_ACCESS_VIOLATION;
1930 } /* if */
1932 while (CharsRemaining >= 1) {
1933 wchCurrent = *lpwstr;
1934 if (wchCurrent >= '0' && wchCurrent <= '9') {
1935 digit = wchCurrent - '0';
1936 } else if (wchCurrent >= 'A' && wchCurrent <= 'Z') {
1937 digit = wchCurrent - 'A' + 10;
1938 } else if (wchCurrent >= 'a' && wchCurrent <= 'z') {
1939 digit = wchCurrent - 'a' + 10;
1940 } else {
1941 digit = -1;
1942 } /* if */
1943 if (digit < 0 || digit >= base) {
1944 *value = bMinus ? -RunningTotal : RunningTotal;
1945 return STATUS_SUCCESS;
1946 } /* if */
1948 RunningTotal = RunningTotal * base + digit;
1949 lpwstr++;
1950 CharsRemaining--;
1951 } /* while */
1953 *value = bMinus ? -RunningTotal : RunningTotal;
1954 return STATUS_SUCCESS;
1958 /**************************************************************************
1959 * RtlIntegerToUnicodeString (NTDLL.@)
1961 * Converts an unsigned integer to a '\0' terminated unicode string.
1963 * RETURNS
1964 * Success: STATUS_SUCCESS. str contains the converted number
1965 * Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
1966 * STATUS_BUFFER_OVERFLOW, if str is too small to hold the string
1967 * (with the '\0' termination). In this case str->Length
1968 * is set to the length, the string would have (which can
1969 * be larger than the MaximumLength).
1971 * NOTES
1972 * Instead of base 0 it uses 10 as base.
1973 * If str is NULL it crashes, as the native function does.
1975 * DIFFERENCES
1976 * Do not return STATUS_BUFFER_OVERFLOW when the string is long enough.
1977 * The native function does this when the string would be longer than 16
1978 * characters even when the string parameter is long enough.
1980 NTSTATUS WINAPI RtlIntegerToUnicodeString(
1981 ULONG value, /* [I] Value to be converted */
1982 ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
1983 UNICODE_STRING *str) /* [O] Destination for the converted value */
1985 WCHAR buffer[33];
1986 PWCHAR pos;
1987 WCHAR digit;
1989 if (base == 0) {
1990 base = 10;
1991 } else if (base != 2 && base != 8 && base != 10 && base != 16) {
1992 return STATUS_INVALID_PARAMETER;
1993 } /* if */
1995 pos = &buffer[32];
1996 *pos = '\0';
1998 do {
1999 pos--;
2000 digit = value % base;
2001 value = value / base;
2002 if (digit < 10) {
2003 *pos = '0' + digit;
2004 } else {
2005 *pos = 'A' + digit - 10;
2006 } /* if */
2007 } while (value != 0L);
2009 str->Length = (&buffer[32] - pos) * sizeof(WCHAR);
2010 if (str->Length >= str->MaximumLength) {
2011 return STATUS_BUFFER_OVERFLOW;
2012 } else {
2013 memcpy(str->Buffer, pos, str->Length + sizeof(WCHAR));
2014 } /* if */
2015 return STATUS_SUCCESS;
2019 /*************************************************************************
2020 * RtlGUIDFromString (NTDLL.@)
2022 * Convert a string representation of a GUID into a GUID.
2024 * PARAMS
2025 * str [I] String representation in the format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
2026 * guid [O] Destination for the converted GUID
2028 * RETURNS
2029 * Success: STATUS_SUCCESS. guid contains the converted value.
2030 * Failure: STATUS_INVALID_PARAMETER, if str is not in the expected format.
2032 * SEE ALSO
2033 * See RtlStringFromGUID.
2035 NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING str, GUID* guid)
2037 int i = 0;
2038 const WCHAR *lpszCLSID = str->Buffer;
2039 BYTE* lpOut = (BYTE*)guid;
2041 TRACE("(%s,%p)\n", debugstr_us(str), guid);
2043 /* Convert string: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
2044 * to memory: DWORD... WORD WORD BYTES............
2046 while (i <= 37)
2048 switch (i)
2050 case 0:
2051 if (*lpszCLSID != '{')
2052 return STATUS_INVALID_PARAMETER;
2053 break;
2055 case 9: case 14: case 19: case 24:
2056 if (*lpszCLSID != '-')
2057 return STATUS_INVALID_PARAMETER;
2058 break;
2060 case 37:
2061 if (*lpszCLSID != '}')
2062 return STATUS_INVALID_PARAMETER;
2063 break;
2065 default:
2067 WCHAR ch = *lpszCLSID, ch2 = lpszCLSID[1];
2068 unsigned char byte;
2070 /* Read two hex digits as a byte value */
2071 if (ch >= '0' && ch <= '9') ch = ch - '0';
2072 else if (ch >= 'a' && ch <= 'f') ch = ch - 'a' + 10;
2073 else if (ch >= 'A' && ch <= 'F') ch = ch - 'A' + 10;
2074 else return STATUS_INVALID_PARAMETER;
2076 if (ch2 >= '0' && ch2 <= '9') ch2 = ch2 - '0';
2077 else if (ch2 >= 'a' && ch2 <= 'f') ch2 = ch2 - 'a' + 10;
2078 else if (ch2 >= 'A' && ch2 <= 'F') ch2 = ch2 - 'A' + 10;
2079 else return STATUS_INVALID_PARAMETER;
2081 byte = ch << 4 | ch2;
2083 switch (i)
2085 #ifndef WORDS_BIGENDIAN
2086 /* For Big Endian machines, we store the data such that the
2087 * dword/word members can be read as DWORDS and WORDS correctly. */
2088 /* Dword */
2089 case 1: lpOut[3] = byte; break;
2090 case 3: lpOut[2] = byte; break;
2091 case 5: lpOut[1] = byte; break;
2092 case 7: lpOut[0] = byte; lpOut += 4; break;
2093 /* Word */
2094 case 10: case 15: lpOut[1] = byte; break;
2095 case 12: case 17: lpOut[0] = byte; lpOut += 2; break;
2096 #endif
2097 /* Byte */
2098 default: lpOut[0] = byte; lpOut++; break;
2100 lpszCLSID++; /* Skip 2nd character of byte */
2101 i++;
2104 lpszCLSID++;
2105 i++;
2108 return STATUS_SUCCESS;
2111 /*************************************************************************
2112 * RtlStringFromGUID (NTDLL.@)
2114 * Convert a GUID into a string representation of a GUID.
2116 * PARAMS
2117 * guid [I] GUID to convert
2118 * str [O] Destination for the converted string
2120 * RETURNS
2121 * Success: STATUS_SUCCESS. str contains the converted value.
2122 * Failure: STATUS_NO_MEMORY, if memory for str cannot be allocated.
2124 * SEE ALSO
2125 * See RtlGUIDFromString.
2127 NTSTATUS WINAPI RtlStringFromGUID(const GUID* guid, UNICODE_STRING *str)
2129 static const WCHAR szFormat[] = { '{','%','0','8','l','X','-',
2130 '%','0','4','X','-', '%','0','4','X','-','%','0','2','X','%','0','2','X',
2131 '-', '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
2132 '%','0','2','X','%','0','2','X','}','\0' };
2134 TRACE("(%p,%p)\n", guid, str);
2136 str->Length = GUID_STRING_LENGTH * sizeof(WCHAR);
2137 str->MaximumLength = str->Length + sizeof(WCHAR);
2138 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, str->MaximumLength);
2139 if (!str->Buffer)
2141 str->Length = str->MaximumLength = 0;
2142 return STATUS_NO_MEMORY;
2144 sprintfW(str->Buffer, szFormat, guid->Data1, guid->Data2, guid->Data3,
2145 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
2146 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
2148 return STATUS_SUCCESS;
2151 /******************************************************************************
2152 * RtlHashUnicodeString [NTDLL.@]
2154 NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING string, BOOLEAN case_insensitive, ULONG alg, ULONG *hash)
2156 unsigned int i;
2158 if (!string || !hash) return STATUS_INVALID_PARAMETER;
2160 switch (alg)
2162 case HASH_STRING_ALGORITHM_DEFAULT:
2163 case HASH_STRING_ALGORITHM_X65599:
2164 break;
2165 default:
2166 return STATUS_INVALID_PARAMETER;
2169 *hash = 0;
2170 for (i = 0; i < string->Length/sizeof(WCHAR); i++)
2171 *hash = *hash*65599 + (case_insensitive ? toupperW(string->Buffer[i]) : string->Buffer[i]);
2173 return STATUS_SUCCESS;