3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/rtl/unicode.c
6 * PURPOSE: String functions
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
12 #include <ddk/ntddk.h>
13 #include <ntdll/rtl.h>
14 //#include <internal/nls.h>
16 #include <ntos/minmax.h>
18 #include <ntdll/ntdll.h>
21 extern PUSHORT NlsUnicodeUpcaseTable;
22 extern PUSHORT NlsUnicodeLowercaseTable;
24 WCHAR RtlDowncaseUnicodeChar(IN WCHAR Source);
26 /* FUNCTIONS *****************************************************************/
29 RtlAnsiCharToUnicodeChar (IN CHAR AnsiChar)
36 Size = (NlsLeadByteInfo[AnsiChar] == 0) ? 1 : 2;
39 RtlMultiByteToUnicodeN (&UnicodeChar,
53 RtlAnsiStringToUnicodeSize (IN PANSI_STRING AnsiString)
57 RtlMultiByteToUnicodeSize (&Size,
70 RtlAnsiStringToUnicodeString(
71 IN OUT PUNICODE_STRING DestinationString,
72 IN PANSI_STRING SourceString,
73 IN BOOLEAN AllocateDestinationString)
78 if (NlsMbCodePageTag == TRUE)
79 Length = RtlAnsiStringToUnicodeSize (SourceString);
81 Length = SourceString->Length * sizeof(WCHAR);
84 return STATUS_INVALID_PARAMETER_2;
86 if (AllocateDestinationString == TRUE)
88 DestinationString->MaximumLength = Length + sizeof(WCHAR);
89 DestinationString->Buffer =
90 RtlAllocateHeap (RtlGetProcessHeap (),
92 DestinationString->MaximumLength);
93 if (DestinationString->Buffer == NULL)
94 return STATUS_NO_MEMORY;
98 if (Length + sizeof(WCHAR) > DestinationString->MaximumLength)
100 DPRINT("STATUS_BUFFER_TOO_SMALL\n");
101 return STATUS_BUFFER_TOO_SMALL;
104 DestinationString->Length = Length;
106 RtlZeroMemory (DestinationString->Buffer,
107 DestinationString->Length);
109 Status = RtlMultiByteToUnicodeN (DestinationString->Buffer,
110 DestinationString->Length,
112 SourceString->Buffer,
113 SourceString->Length);
114 if (!NT_SUCCESS(Status))
116 if (AllocateDestinationString)
118 RtlFreeHeap (RtlGetProcessHeap (),
120 DestinationString->Buffer);
125 DestinationString->Buffer[Length / sizeof(WCHAR)] = 0;
127 return STATUS_SUCCESS;
136 RtlAppendAsciizToString(
137 IN OUT PSTRING Destination,
144 return STATUS_SUCCESS;
146 Length = strlen (Source);
147 if (Destination->Length + Length >= Destination->MaximumLength)
148 return STATUS_BUFFER_TOO_SMALL;
150 Ptr = Destination->Buffer + Destination->Length;
157 Destination->Length += Length;
159 return STATUS_SUCCESS;
168 RtlAppendStringToString(
169 IN OUT PSTRING Destination,
174 if (Source->Length == 0)
175 return STATUS_SUCCESS;
177 if (Destination->Length + Source->Length >= Destination->MaximumLength)
178 return STATUS_BUFFER_TOO_SMALL;
180 Ptr = Destination->Buffer + Destination->Length;
184 Ptr += Source->Length;
187 Destination->Length += Source->Length;
189 return STATUS_SUCCESS;
198 RtlAppendUnicodeStringToString(
199 IN OUT PUNICODE_STRING Destination,
200 IN PUNICODE_STRING Source)
203 if ((Source->Length + Destination->Length) >= Destination->MaximumLength)
204 return STATUS_BUFFER_TOO_SMALL;
206 memcpy((PVOID)Destination->Buffer + Destination->Length, Source->Buffer, Source->Length);
207 Destination->Length += Source->Length;
208 Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0;
210 return STATUS_SUCCESS;
218 RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
223 slen = wcslen(Source) * sizeof(WCHAR);
225 if (Destination->Length + slen >= Destination->MaximumLength)
226 return(STATUS_BUFFER_TOO_SMALL);
228 memcpy((PVOID)Destination->Buffer + Destination->Length, Source, slen);
229 Destination->Length += slen;
230 Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0;
232 return(STATUS_SUCCESS);
257 if ((*String == 'x') && isxdigit (String[1]))
265 if (!isxdigit (*String))
266 return STATUS_INVALID_PARAMETER;
268 while (isxdigit (*String) &&
269 (Val = isdigit (*String) ? * String - '0' : (islower (*String)
270 ? toupper (*String) : *String) - 'A' + 10) < Base)
272 *Value = *Value * Base + Val;
276 return STATUS_SUCCESS;
288 IN BOOLEAN CaseInsensitive)
294 if (String1 && String2)
296 len1 = String1->Length;
297 len2 = String2->Length;
298 s1 = String1->Buffer;
299 s2 = String2->Buffer;
307 c1 = len1-- ? RtlUpperChar (*s1++) : 0;
308 c2 = len2-- ? RtlUpperChar (*s2++) : 0;
309 if (!c1 || !c2 || c1 != c2)
317 c1 = len1-- ? *s1++ : 0;
318 c2 = len2-- ? *s2++ : 0;
319 if (!c1 || !c2 || c1 != c2)
335 RtlCompareUnicodeString(
336 IN PUNICODE_STRING String1,
337 IN PUNICODE_STRING String2,
338 IN BOOLEAN CaseInsensitive)
344 if (String1 && String2)
346 len1 = String1->Length / sizeof(WCHAR);
347 len2 = String2->Length / sizeof(WCHAR);
348 s1 = String1->Buffer;
349 s2 = String2->Buffer;
357 c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
358 c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
359 if (!c1 || !c2 || c1 != c2)
367 c1 = len1-- ? *s1++ : 0;
368 c2 = len2-- ? *s2++ : 0;
369 if (!c1 || !c2 || c1 != c2)
386 IN OUT PSTRING DestinationString,
387 IN PSTRING SourceString)
391 if (SourceString == NULL)
393 DestinationString->Length = 0;
397 copylen = min (DestinationString->MaximumLength - sizeof(CHAR),
398 SourceString->Length);
399 memcpy(DestinationString->Buffer, SourceString->Buffer, copylen);
400 DestinationString->Length = copylen;
401 DestinationString->Buffer[copylen] = 0;
410 RtlCopyUnicodeString(
411 IN OUT PUNICODE_STRING DestinationString,
412 IN PUNICODE_STRING SourceString)
416 if (SourceString == NULL)
418 DestinationString->Length = 0;
422 copylen = min (DestinationString->MaximumLength - sizeof(WCHAR),
423 SourceString->Length);
424 memcpy(DestinationString->Buffer, SourceString->Buffer, copylen);
425 DestinationString->Buffer[copylen / sizeof(WCHAR)] = 0;
426 DestinationString->Length = copylen;
435 RtlCreateUnicodeString(
436 IN OUT PUNICODE_STRING Destination,
441 Length = (wcslen (Source) + 1) * sizeof(WCHAR);
443 Destination->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
446 if (Destination->Buffer == NULL)
449 memmove (Destination->Buffer,
453 Destination->MaximumLength = Length;
454 Destination->Length = Length - sizeof (WCHAR);
465 RtlCreateUnicodeStringFromAsciiz(
466 OUT PUNICODE_STRING Destination,
469 ANSI_STRING AnsiString;
472 RtlInitAnsiString (&AnsiString,
475 Status = RtlAnsiStringToUnicodeString (Destination,
479 return NT_SUCCESS(Status);
488 RtlDowncaseUnicodeString(
489 IN OUT PUNICODE_STRING DestinationString,
490 IN PUNICODE_STRING SourceString,
491 IN BOOLEAN AllocateDestinationString)
496 if (AllocateDestinationString == TRUE)
498 DestinationString->MaximumLength = SourceString->Length + sizeof(WCHAR);
499 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
501 SourceString->Length + sizeof(WCHAR));
505 if (SourceString->Length >= DestinationString->MaximumLength)
506 return STATUS_BUFFER_TOO_SMALL;
508 DestinationString->Length = SourceString->Length;
510 Src = SourceString->Buffer;
511 Dest = DestinationString->Buffer;
512 for (i=0; i < SourceString->Length / sizeof(WCHAR); i++)
518 else if (*Src <= L'Z')
520 *Dest = (*Src + (L'a' - L'A'));
524 *Dest = RtlDowncaseUnicodeChar(*Src);
532 return STATUS_SUCCESS;
541 RtlEqualComputerName(
542 IN PUNICODE_STRING ComputerName1,
543 IN PUNICODE_STRING ComputerName2)
545 return RtlEqualDomainName (ComputerName1,
556 IN PUNICODE_STRING DomainName1,
557 IN PUNICODE_STRING DomainName2
560 OEM_STRING OemString1;
561 OEM_STRING OemString2;
564 RtlUpcaseUnicodeStringToOemString (&OemString1,
567 RtlUpcaseUnicodeStringToOemString (&OemString2,
571 Result = RtlEqualString (&OemString1,
575 RtlFreeOemString (&OemString1);
576 RtlFreeOemString (&OemString2);
590 IN BOOLEAN CaseInsensitive)
596 if (String1->Length != String2->Length)
599 p1 = String1->Buffer;
600 p2 = String2->Buffer;
601 for (i = 0; i < String1->Length; i++)
603 if (CaseInsensitive == TRUE)
605 c1 = RtlUpperChar (*p1);
606 c2 = RtlUpperChar (*p2);
630 RtlEqualUnicodeString(
631 IN PUNICODE_STRING String1,
632 IN PUNICODE_STRING String2,
633 IN BOOLEAN CaseInsensitive)
639 if (String1->Length != String2->Length)
642 pw1 = String1->Buffer;
643 pw2 = String2->Buffer;
645 for (i = 0; i < String1->Length / sizeof(WCHAR); i++)
647 if (CaseInsensitive == TRUE)
649 wc1 = RtlUpcaseUnicodeChar (*pw1);
650 wc2 = RtlUpcaseUnicodeChar (*pw2);
674 RtlEraseUnicodeString(
675 IN PUNICODE_STRING String)
677 if (String->Buffer == NULL)
680 if (String->MaximumLength == 0)
683 memset (String->Buffer,
685 String->MaximumLength);
697 IN PANSI_STRING AnsiString)
699 if (AnsiString->Buffer == NULL)
702 RtlFreeHeap (RtlGetProcessHeap (),
706 AnsiString->Buffer = NULL;
707 AnsiString->Length = 0;
708 AnsiString->MaximumLength = 0;
718 IN POEM_STRING OemString)
720 if (OemString->Buffer == NULL)
723 RtlFreeHeap (RtlGetProcessHeap (),
727 OemString->Buffer = NULL;
728 OemString->Length = 0;
729 OemString->MaximumLength = 0;
738 RtlFreeUnicodeString(
739 IN PUNICODE_STRING UnicodeString)
741 if (UnicodeString->Buffer == NULL)
744 RtlFreeHeap (RtlGetProcessHeap (),
746 UnicodeString->Buffer);
748 UnicodeString->Buffer = NULL;
749 UnicodeString->Length = 0;
750 UnicodeString->MaximumLength = 0;
760 IN OUT PANSI_STRING DestinationString,
761 IN PCSZ SourceString)
765 if(SourceString==NULL)
767 DestinationString->Length = 0;
768 DestinationString->MaximumLength = 0;
772 DestSize = strlen ((const char *)SourceString);
773 DestinationString->Length = DestSize;
774 DestinationString->MaximumLength = DestSize + 1;
776 DestinationString->Buffer = (PCHAR)SourceString;
786 IN OUT PSTRING DestinationString,
787 IN PCSZ SourceString)
791 if (SourceString == NULL)
793 DestinationString->Length = 0;
794 DestinationString->MaximumLength = 0;
798 DestSize = strlen((const char *)SourceString);
799 DestinationString->Length = DestSize;
800 DestinationString->MaximumLength = DestSize + sizeof(CHAR);
802 DestinationString->Buffer = (PCHAR)SourceString;
811 RtlInitUnicodeString(
812 IN OUT PUNICODE_STRING DestinationString,
813 IN PCWSTR SourceString)
817 if (SourceString==NULL)
819 DestinationString->Length=0;
820 DestinationString->MaximumLength=0;
824 DestSize = wcslen((PWSTR)SourceString) * sizeof(WCHAR);
825 DestinationString->Length = DestSize;
826 DestinationString->MaximumLength = DestSize + sizeof(WCHAR);
828 DestinationString->Buffer = (PWSTR)SourceString;
854 if ((Radix != 2) && (Radix != 8) &&
855 (Radix != 10) && (Radix != 16))
856 return STATUS_INVALID_PARAMETER;
859 while (v || tp == temp)
870 if (tp - temp >= Length)
871 return STATUS_BUFFER_TOO_SMALL;
878 return STATUS_SUCCESS;
887 RtlIntegerToUnicodeString(
889 IN ULONG Base, /* optional */
890 IN OUT PUNICODE_STRING String)
892 ANSI_STRING AnsiString;
896 Status = RtlIntegerToChar (Value,
900 if (!NT_SUCCESS(Status))
903 AnsiString.Buffer = Buffer;
904 AnsiString.Length = strlen (Buffer);
905 AnsiString.MaximumLength = 33;
907 Status = RtlAnsiStringToUnicodeString (String,
915 #define ITU_IMPLEMENTED_TESTS (IS_TEXT_UNICODE_ODD_LENGTH|IS_TEXT_UNICODE_SIGNATURE)
921 RtlIsTextUnicode (PVOID Buffer,
926 ULONG in_flags = (ULONG)-1;
936 * Apply various tests to the text string. According to the
937 * docs, each test "passed" sets the corresponding flag in
938 * the output flags. But some of the tests are mutually
939 * exclusive, so I don't see how you could pass all tests ...
942 /* Check for an odd length ... pass if even. */
944 out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
946 /* Check for the BOM (byte order mark). */
948 out_flags |= IS_TEXT_UNICODE_SIGNATURE;
951 /* Check for the reverse BOM (byte order mark). */
953 out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
956 /* FIXME: Add more tests */
959 * Check whether the string passed all of the tests.
961 in_flags &= ITU_IMPLEMENTED_TESTS;
962 if ((out_flags & in_flags) != in_flags)
978 RtlLargeIntegerToChar(
979 IN PLARGE_INTEGER Value,
986 ULONGLONG v = Value->QuadPart;
995 if ((Radix != 2) && (Radix != 8) &&
996 (Radix != 10) && (Radix != 16))
997 return STATUS_INVALID_PARAMETER;
1000 while (v || tp == temp)
1011 if (tp - temp >= Length)
1012 return STATUS_BUFFER_TOO_SMALL;
1019 return STATUS_SUCCESS;
1028 RtlOemStringToUnicodeSize(
1029 IN POEM_STRING OemString)
1033 RtlMultiByteToUnicodeSize (&Size,
1046 RtlOemStringToUnicodeString(
1047 IN OUT PUNICODE_STRING DestinationString,
1048 IN POEM_STRING SourceString,
1049 IN BOOLEAN AllocateDestinationString)
1054 if (NlsMbCodePageTag == TRUE)
1055 Length = RtlAnsiStringToUnicodeSize (SourceString);
1057 Length = SourceString->Length * sizeof(WCHAR);
1060 return STATUS_INVALID_PARAMETER_2;
1062 if (AllocateDestinationString == TRUE)
1064 DestinationString->MaximumLength = Length + sizeof(WCHAR);
1065 DestinationString->Buffer =
1066 RtlAllocateHeap (RtlGetProcessHeap (),
1068 DestinationString->MaximumLength);
1069 if (DestinationString->Buffer == NULL)
1070 return STATUS_NO_MEMORY;
1074 if (Length + sizeof(WCHAR) > DestinationString->MaximumLength)
1076 DPRINT("STATUS_BUFFER_TOO_SMALL\n");
1077 return STATUS_BUFFER_TOO_SMALL;
1080 DestinationString->Length = Length;
1082 RtlZeroMemory (DestinationString->Buffer,
1083 DestinationString->Length);
1085 Status = RtlOemToUnicodeN (DestinationString->Buffer,
1086 DestinationString->Length,
1088 SourceString->Buffer,
1089 SourceString->Length);
1090 if (!NT_SUCCESS(Status))
1092 if (AllocateDestinationString)
1094 RtlFreeHeap (RtlGetProcessHeap (),
1096 DestinationString->Buffer);
1101 DestinationString->Buffer[Length / sizeof(WCHAR)] = 0;
1103 return STATUS_SUCCESS;
1113 PANSI_STRING String1,
1114 PANSI_STRING String2,
1115 BOOLEAN CaseInsensitive)
1121 if (String2->Length < String1->Length)
1124 Length = String1->Length;
1125 pc1 = String1->Buffer;
1126 pc2 = String2->Buffer;
1130 if (CaseInsensitive)
1134 if (RtlUpperChar (*pc1++) != RtlUpperChar (*pc2++))
1142 if (*pc1++ != *pc2++)
1157 RtlPrefixUnicodeString(
1158 PUNICODE_STRING String1,
1159 PUNICODE_STRING String2,
1160 BOOLEAN CaseInsensitive)
1166 if (String2->Length < String1->Length)
1169 Length = String1->Length / 2;
1170 pc1 = String1->Buffer;
1171 pc2 = String2->Buffer;
1175 if (CaseInsensitive)
1179 if (RtlUpcaseUnicodeChar (*pc1++)
1180 != RtlUpcaseUnicodeChar (*pc2++))
1188 if( *pc1++ != *pc2++ )
1203 RtlUnicodeStringToAnsiSize(
1204 IN PUNICODE_STRING UnicodeString)
1208 RtlUnicodeToMultiByteSize (&Size,
1209 UnicodeString->Buffer,
1210 UnicodeString->Length);
1212 return Size+1; //NB: incl. nullterm
1221 RtlUnicodeStringToAnsiString(
1222 IN OUT PANSI_STRING DestinationString,
1223 IN PUNICODE_STRING SourceString,
1224 IN BOOLEAN AllocateDestinationString)
1229 if (NlsMbCodePageTag == TRUE)
1230 Length = RtlUnicodeStringToAnsiSize (SourceString);
1232 Length = SourceString->Length / sizeof(WCHAR);
1234 if (AllocateDestinationString == TRUE)
1236 DestinationString->MaximumLength = Length + sizeof(CHAR);
1237 DestinationString->Buffer =
1238 RtlAllocateHeap (RtlGetProcessHeap (),
1240 DestinationString->MaximumLength);
1241 if (DestinationString->Buffer == NULL)
1242 return STATUS_NO_MEMORY;
1246 if (Length >= DestinationString->MaximumLength)
1247 return STATUS_BUFFER_TOO_SMALL;
1249 DestinationString->Length = Length;
1251 RtlZeroMemory (DestinationString->Buffer,
1252 DestinationString->Length);
1254 Status = RtlUnicodeToMultiByteN (DestinationString->Buffer,
1255 DestinationString->Length,
1257 SourceString->Buffer,
1258 SourceString->Length);
1259 if (!NT_SUCCESS(Status))
1261 if (AllocateDestinationString == TRUE)
1263 RtlFreeHeap (RtlGetProcessHeap (),
1265 DestinationString->Buffer);
1270 DestinationString->Buffer[Length] = 0;
1272 return STATUS_SUCCESS;
1281 RtlUnicodeStringToInteger(
1282 IN PUNICODE_STRING String,
1290 BOOLEAN addneg = FALSE;
1293 Str = String->Buffer;
1295 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
1302 else if (*Str == L'o')
1307 else if (*Str == L'd')
1312 else if (*Str == L'x')
1317 else if (*Str == L'+')
1321 else if (*Str == L'-')
1326 else if ((*Str > L'1') && (Base == 2))
1328 return STATUS_INVALID_PARAMETER;
1330 else if (((*Str > L'7') || (*Str < L'0')) && (Base == 8))
1332 return STATUS_INVALID_PARAMETER;
1334 else if (((*Str > L'9') || (*Str < L'0')) && (Base == 10))
1336 return STATUS_INVALID_PARAMETER;
1338 else if ((((*Str > L'9') || (*Str < L'0')) ||
1339 ((towupper (*Str) > L'F') ||
1340 (towupper (*Str) < L'A'))) && (Base == 16))
1342 return STATUS_INVALID_PARAMETER;
1348 Str = String->Buffer + lenmin;
1353 while (iswxdigit (*Str) &&
1354 (Val = iswdigit (*Str) ? *Str - L'0' : (iswlower (*Str)
1355 ? toupper (*Str) : *Str) - L'A' + 10) < Base)
1357 *Value = *Value * Base + Val;
1364 return STATUS_SUCCESS;
1373 RtlUnicodeStringToOemSize(
1374 IN PUNICODE_STRING UnicodeString)
1378 RtlUnicodeToMultiByteSize (&Size,
1379 UnicodeString->Buffer,
1380 UnicodeString->Length);
1382 return Size+1; //NB: incl. nullterm
1391 RtlUnicodeStringToCountedOemString(
1392 IN OUT POEM_STRING DestinationString,
1393 IN PUNICODE_STRING SourceString,
1394 IN BOOLEAN AllocateDestinationString)
1400 if (NlsMbOemCodePageTag == TRUE)
1401 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1403 Length = SourceString->Length / sizeof(WCHAR) + 1;
1405 if (Length > 0x0000FFFF)
1406 return STATUS_INVALID_PARAMETER_2;
1408 DestinationString->Length = (WORD)(Length - 1);
1410 if (AllocateDestinationString)
1412 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1415 if (DestinationString->Buffer == NULL)
1416 return STATUS_NO_MEMORY;
1418 RtlZeroMemory (DestinationString->Buffer,
1420 DestinationString->MaximumLength = (WORD)Length;
1424 if (Length > DestinationString->MaximumLength)
1426 if (DestinationString->MaximumLength == 0)
1427 return STATUS_BUFFER_OVERFLOW;
1428 DestinationString->Length =
1429 DestinationString->MaximumLength - 1;
1433 Status = RtlUnicodeToOemN (DestinationString->Buffer,
1434 DestinationString->Length,
1436 SourceString->Buffer,
1437 SourceString->Length);
1438 if (!NT_SUCCESS(Status))
1440 if (AllocateDestinationString)
1442 RtlFreeHeap (RtlGetProcessHeap (),
1444 DestinationString->Buffer);
1449 DestinationString->Buffer[Size] = 0;
1451 return STATUS_SUCCESS;
1460 RtlUnicodeStringToOemString(
1461 IN OUT POEM_STRING DestinationString,
1462 IN PUNICODE_STRING SourceString,
1463 IN BOOLEAN AllocateDestinationString)
1469 if (NlsMbOemCodePageTag == TRUE)
1470 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1472 Length = SourceString->Length / sizeof(WCHAR) + 1;
1474 if (Length > 0x0000FFFF)
1475 return STATUS_INVALID_PARAMETER_2;
1477 DestinationString->Length = (WORD)(Length - 1);
1479 if (AllocateDestinationString)
1481 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1484 if (DestinationString->Buffer == NULL)
1485 return STATUS_NO_MEMORY;
1487 RtlZeroMemory (DestinationString->Buffer,
1489 DestinationString->MaximumLength = (WORD)Length;
1493 if (Length > DestinationString->MaximumLength)
1495 if (DestinationString->MaximumLength == 0)
1496 return STATUS_BUFFER_OVERFLOW;
1497 DestinationString->Length =
1498 DestinationString->MaximumLength - 1;
1502 Status = RtlUnicodeToOemN (DestinationString->Buffer,
1503 DestinationString->Length,
1505 SourceString->Buffer,
1506 SourceString->Length);
1507 if (!NT_SUCCESS(Status))
1509 if (AllocateDestinationString)
1511 RtlFreeHeap (RtlGetProcessHeap (),
1513 DestinationString->Buffer);
1518 DestinationString->Buffer[Size] = 0;
1520 return STATUS_SUCCESS;
1529 RtlUpcaseUnicodeString(
1530 IN OUT PUNICODE_STRING DestinationString,
1531 IN PCUNICODE_STRING SourceString,
1532 IN BOOLEAN AllocateDestinationString)
1537 if (AllocateDestinationString == TRUE)
1539 DestinationString->MaximumLength=SourceString->Length+sizeof(WCHAR);
1540 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1542 SourceString->Length + sizeof(WCHAR));
1543 if (DestinationString->Buffer == NULL)
1544 return STATUS_NO_MEMORY;
1548 if (SourceString->Length >= DestinationString->MaximumLength)
1549 return STATUS_BUFFER_TOO_SMALL;
1551 DestinationString->Length = SourceString->Length;
1553 Src = SourceString->Buffer;
1554 Dest = DestinationString->Buffer;
1555 for (i = 0; i < SourceString->Length / sizeof(WCHAR); i++)
1557 *Dest = RtlUpcaseUnicodeChar (*Src);
1563 return STATUS_SUCCESS;
1572 RtlUpcaseUnicodeStringToAnsiString(
1573 IN OUT PANSI_STRING DestinationString,
1574 IN PUNICODE_STRING SourceString,
1575 IN BOOLEAN AllocateDestinationString)
1581 if (NlsMbCodePageTag == TRUE)
1582 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1584 Length = SourceString->Length / sizeof(WCHAR) + 1;
1586 if (Length > 0x0000FFFF)
1587 return STATUS_INVALID_PARAMETER_2;
1589 DestinationString->Length = (WORD)(Length - 1);
1591 if (AllocateDestinationString == TRUE)
1593 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1595 DestinationString->MaximumLength);
1596 if (DestinationString->Buffer == NULL)
1597 return STATUS_NO_MEMORY;
1599 RtlZeroMemory (DestinationString->Buffer,
1601 DestinationString->MaximumLength = (WORD)Length;
1605 if (Length > DestinationString->MaximumLength)
1607 if (!DestinationString->MaximumLength)
1608 return STATUS_BUFFER_OVERFLOW;
1609 DestinationString->Length =
1610 DestinationString->MaximumLength - 1;
1614 Status = RtlUpcaseUnicodeToMultiByteN (DestinationString->Buffer,
1615 DestinationString->Length,
1617 SourceString->Buffer,
1618 SourceString->Length);
1619 if (!NT_SUCCESS(Status))
1621 if (AllocateDestinationString)
1623 RtlFreeHeap (RtlGetProcessHeap (),
1625 DestinationString->Buffer);
1630 DestinationString->Buffer[Size] = 0;
1632 return STATUS_SUCCESS;
1641 RtlUpcaseUnicodeStringToCountedOemString(
1642 IN OUT POEM_STRING DestinationString,
1643 IN PUNICODE_STRING SourceString,
1644 IN BOOLEAN AllocateDestinationString)
1650 if (NlsMbCodePageTag == TRUE)
1651 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1653 Length = SourceString->Length / sizeof(WCHAR) + 1;
1655 if (Length > 0x0000FFFF)
1656 return STATUS_INVALID_PARAMETER_2;
1658 DestinationString->Length = (WORD)(Length - 1);
1660 if (AllocateDestinationString == TRUE)
1662 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1665 if (DestinationString->Buffer == NULL)
1666 return STATUS_NO_MEMORY;
1668 RtlZeroMemory (DestinationString->Buffer,
1670 DestinationString->MaximumLength = (WORD)Length;
1674 if (Length > DestinationString->MaximumLength)
1676 if (DestinationString->MaximumLength == 0)
1677 return STATUS_BUFFER_OVERFLOW;
1678 DestinationString->Length =
1679 DestinationString->MaximumLength - 1;
1683 Status = RtlUpcaseUnicodeToOemN (DestinationString->Buffer,
1684 DestinationString->Length,
1686 SourceString->Buffer,
1687 SourceString->Length);
1688 if (!NT_SUCCESS(Status))
1690 if (AllocateDestinationString)
1692 RtlFreeHeap (RtlGetProcessHeap (),
1694 DestinationString->Buffer);
1699 DestinationString->Buffer[Size] = 0;
1701 return STATUS_SUCCESS;
1710 RtlUpcaseUnicodeStringToOemString (
1711 IN OUT POEM_STRING DestinationString,
1712 IN PUNICODE_STRING SourceString,
1713 IN BOOLEAN AllocateDestinationString
1720 if (NlsMbOemCodePageTag == TRUE)
1721 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1723 Length = SourceString->Length / sizeof(WCHAR) + 1;
1725 if (Length > 0x0000FFFF)
1726 return STATUS_INVALID_PARAMETER_2;
1728 DestinationString->Length = (WORD)(Length - 1);
1730 if (AllocateDestinationString == TRUE)
1732 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1735 if (DestinationString->Buffer == NULL)
1736 return STATUS_NO_MEMORY;
1738 RtlZeroMemory (DestinationString->Buffer,
1740 DestinationString->MaximumLength = (WORD)Length;
1744 if (Length > DestinationString->MaximumLength)
1746 if (DestinationString->MaximumLength == 0)
1747 return STATUS_BUFFER_OVERFLOW;
1748 DestinationString->Length =
1749 DestinationString->MaximumLength - 1;
1753 Status = RtlUpcaseUnicodeToOemN (DestinationString->Buffer,
1754 DestinationString->Length,
1756 SourceString->Buffer,
1757 SourceString->Length);
1758 if (!NT_SUCCESS(Status))
1760 if (AllocateDestinationString)
1762 RtlFreeHeap (RtlGetProcessHeap (),
1764 DestinationString->Buffer);
1769 DestinationString->Buffer[Size] = 0;
1771 return STATUS_SUCCESS;
1779 RtlUpperString (IN OUT PSTRING DestinationString,
1780 IN PSTRING SourceString)
1787 Length = min(SourceString->Length, DestinationString->MaximumLength - 1);
1789 Src = SourceString->Buffer;
1790 Dest = DestinationString->Buffer;
1791 for (i = 0; i < Length; i++)
1793 *Dest = RtlUpperChar (*Src);
1799 DestinationString->Length = SourceString->Length;
1807 RtlxAnsiStringToUnicodeSize (IN PANSI_STRING AnsiString)
1809 return RtlAnsiStringToUnicodeSize (AnsiString);
1817 RtlxOemStringToUnicodeSize (IN POEM_STRING OemString)
1819 return RtlAnsiStringToUnicodeSize ((PANSI_STRING)OemString);
1827 RtlxUnicodeStringToAnsiSize (IN PUNICODE_STRING UnicodeString)
1829 return RtlUnicodeStringToAnsiSize (UnicodeString);
1837 RtlxUnicodeStringToOemSize (IN PUNICODE_STRING UnicodeString)
1839 return RtlUnicodeStringToAnsiSize (UnicodeString);