Changeset 8429 for trunk/src/NTDLL/rtlstr.c
- Timestamp:
- May 16, 2002, 2:22:14 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/NTDLL/rtlstr.c
r7983 r8429 4 4 * Copyright (C) 1996-1998 Marcus Meissner 5 5 * Copyright (C) 2000 Alexandre Julliard 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 20 */ 7 21 8 22 #include "config.h" 9 23 24 #include <assert.h> 10 25 #include <stdlib.h> 11 26 #include <string.h> 12 27 #include <ctype.h> 28 29 #include "ntddk.h" 13 30 #include "wine/unicode.h" 14 #include "heap.h" 15 #include "winnls.h" 16 #include "debugtools.h" 17 #include "ntdll_misc.h" 18 #include "ntddk.h" 19 #include "unicode.h" 20 21 DEFAULT_DEBUG_CHANNEL(ntdll); 22 23 /* STRING CREATION FUNCTIONS */ 31 #include "wine/debug.h" 32 33 WINE_DEFAULT_DEBUG_CHANNEL(ntdll); 34 35 UINT NlsAnsiCodePage = 1252; 36 BYTE NlsMbCodePageTag = 0; 37 BYTE NlsMbOemCodePageTag = 0; 38 39 static const union cptable *ansi_table; 40 static const union cptable *oem_table; 41 42 inline static const union cptable *get_ansi_table(void) 43 { 44 if (!ansi_table) ansi_table = cp_get_table( 1252 ); 45 return ansi_table; 46 } 47 48 inline static const union cptable *get_oem_table(void) 49 { 50 if (!oem_table) oem_table = cp_get_table( 437 ); 51 return oem_table; 52 } 53 54 55 /************************************************************************** 56 * __wine_init_codepages (NTDLL.@) 57 * 58 * Set the code page once kernel32 is loaded. Should be done differently. 59 */ 60 void __wine_init_codepages( const union cptable *ansi, const union cptable *oem ) 61 { 62 ansi_table = ansi; 63 oem_table = oem; 64 NlsAnsiCodePage = ansi->info.codepage; 65 } 66 24 67 25 68 /************************************************************************** … … 42 85 void WINAPI RtlInitString( PSTRING target, LPCSTR source ) 43 86 { 44 //return RtlInitAnsiString( target, source ); /* WATCOM: can't return void */ 45 RtlInitAnsiString( target, source ); 87 return RtlInitAnsiString( target, source ); 46 88 } 47 89 … … 52 94 void WINAPI RtlFreeAnsiString( PSTRING str ) 53 95 { 54 if (str->Buffer) HeapFree( GetProcessHeap(), 0, str->Buffer );96 if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer ); 55 97 } 56 98 … … 100 142 { 101 143 int len = (strlenW(src) + 1) * sizeof(WCHAR); 102 if (!(target->Buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;144 if (!(target->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return FALSE; 103 145 memcpy( target->Buffer, src, len ); 104 146 target->MaximumLength = len; … … 124 166 void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str ) 125 167 { 126 if (str->Buffer) HeapFree( GetProcessHeap(), 0, str->Buffer );168 if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer ); 127 169 } 128 170 … … 301 343 BOOLEAN doalloc ) 302 344 { 303 DWORD len = MultiByteToWideChar( CP_ACP, 0, ansi->Buffer, ansi->Length, NULL, 0 ); 304 DWORD total = (len + 1) * sizeof(WCHAR); 345 DWORD total = RtlAnsiStringToUnicodeSize( ansi ); 305 346 306 347 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2; 307 uni->Length = len *sizeof(WCHAR);348 uni->Length = total - sizeof(WCHAR); 308 349 if (doalloc) 309 350 { 310 351 uni->MaximumLength = total; 311 if (!(uni->Buffer = HeapAlloc( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY;352 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY; 312 353 } 313 354 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW; 314 355 315 MultiByteToWideChar( CP_ACP, 0, ansi->Buffer, ansi->Length, uni->Buffer, len);316 uni->Buffer[ len] = 0;356 RtlMultiByteToUnicodeN( uni->Buffer, uni->Length, NULL, ansi->Buffer, ansi->Length ); 357 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0; 317 358 return STATUS_SUCCESS; 318 359 } … … 330 371 BOOLEAN doalloc ) 331 372 { 332 DWORD len = MultiByteToWideChar( CP_OEMCP, 0, oem->Buffer, oem->Length, NULL, 0 ); 333 DWORD total = (len + 1) * sizeof(WCHAR); 373 DWORD total = RtlOemStringToUnicodeSize( oem ); 334 374 335 375 if (total > 0xffff) return STATUS_INVALID_PARAMETER_2; 336 uni->Length = len *sizeof(WCHAR);376 uni->Length = total - sizeof(WCHAR); 337 377 if (doalloc) 338 378 { 339 379 uni->MaximumLength = total; 340 if (!(uni->Buffer = HeapAlloc( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY;380 if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY; 341 381 } 342 382 else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW; 343 383 344 MultiByteToWideChar( CP_OEMCP, 0, oem->Buffer, oem->Length, uni->Buffer, len);345 uni->Buffer[ len] = 0;384 RtlOemToUnicodeN( uni->Buffer, uni->Length, NULL, oem->Buffer, oem->Length ); 385 uni->Buffer[uni->Length / sizeof(WCHAR)] = 0; 346 386 return STATUS_SUCCESS; 347 387 } … … 362 402 DWORD len = RtlUnicodeStringToAnsiSize( uni ); 363 403 364 ansi->Length = len ;404 ansi->Length = len - 1; 365 405 if (doalloc) 366 406 { 367 ansi->MaximumLength = len + 1;368 if (!(ansi->Buffer = HeapAlloc( GetProcessHeap(), 0, len + 1))) return STATUS_NO_MEMORY;369 } 370 else if (ansi->MaximumLength < =len)407 ansi->MaximumLength = len; 408 if (!(ansi->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY; 409 } 410 else if (ansi->MaximumLength < len) 371 411 { 372 412 if (!ansi->MaximumLength) return STATUS_BUFFER_OVERFLOW; … … 375 415 } 376 416 377 WideCharToMultiByte( CP_ACP, 0, uni->Buffer, uni->Length / sizeof(WCHAR), 378 ansi->Buffer, ansi->Length, NULL, NULL ); 417 RtlUnicodeToMultiByteN( ansi->Buffer, ansi->Length, NULL, uni->Buffer, uni->Length ); 379 418 ansi->Buffer[ansi->Length] = 0; 380 419 return ret; … … 396 435 DWORD len = RtlUnicodeStringToOemSize( uni ); 397 436 398 oem->Length = len ;437 oem->Length = len - 1; 399 438 if (doalloc) 400 439 { 401 oem->MaximumLength = len + 1;402 if (!(oem->Buffer = HeapAlloc( GetProcessHeap(), 0, len + 1))) return STATUS_NO_MEMORY;403 } 404 else if (oem->MaximumLength < =len)440 oem->MaximumLength = len; 441 if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY; 442 } 443 else if (oem->MaximumLength < len) 405 444 { 406 445 if (!oem->MaximumLength) return STATUS_BUFFER_OVERFLOW; … … 409 448 } 410 449 411 WideCharToMultiByte( CP_OEMCP, 0, uni->Buffer, uni->Length / sizeof(WCHAR), 412 oem->Buffer, oem->Length, NULL, NULL ); 450 RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, uni->Buffer, uni->Length ); 413 451 oem->Buffer[oem->Length] = 0; 414 452 return ret; … … 425 463 LPCSTR src, DWORD srclen ) 426 464 { 427 DWORD res = MultiByteToWideChar( CP_ACP, 0, src, srclen, dst, dstlen/sizeof(WCHAR) ); 465 466 int ret = cp_mbstowcs( get_ansi_table(), 0, src, srclen, dst, dstlen/sizeof(WCHAR) ); 428 467 if (reslen) 429 *reslen = res ? res *sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */468 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */ 430 469 return STATUS_SUCCESS; 431 470 } … … 438 477 LPCSTR src, DWORD srclen ) 439 478 { 440 DWORD res = MultiByteToWideChar( CP_OEMCP, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );479 int ret = cp_mbstowcs( get_oem_table(), 0, src, srclen, dst, dstlen/sizeof(WCHAR) ); 441 480 if (reslen) 442 *reslen = res ? res *sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */481 *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */ 443 482 return STATUS_SUCCESS; 444 483 } … … 451 490 LPCWSTR src, DWORD srclen ) 452 491 { 453 DWORD res = WideCharToMultiByte( CP_ACP, 0, src, srclen/sizeof(WCHAR),454 492 int ret = cp_wcstombs( get_ansi_table(), 0, src, srclen / sizeof(WCHAR), 493 dst, dstlen, NULL, NULL ); 455 494 if (reslen) 456 *reslen = res ? res * sizeof(WCHAR): dstlen; /* overflow -> we filled up to dstlen */495 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */ 457 496 return STATUS_SUCCESS; 458 497 } … … 465 504 LPCWSTR src, DWORD srclen ) 466 505 { 467 DWORD res = WideCharToMultiByte( CP_OEMCP, 0, src, srclen/sizeof(WCHAR),468 506 int ret = cp_wcstombs( get_oem_table(), 0, src, srclen / sizeof(WCHAR), 507 dst, dstlen, NULL, NULL ); 469 508 if (reslen) 470 *reslen = res ? res * sizeof(WCHAR): dstlen; /* overflow -> we filled up to dstlen */509 *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */ 471 510 return STATUS_SUCCESS; 472 511 } … … 506 545 { 507 546 dest->MaximumLength = len; 508 if (!(dest->Buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY;547 if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY; 509 548 } 510 549 else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW; … … 570 609 DWORD i; 571 610 572 if (!(upcase = HeapAlloc( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;611 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY; 573 612 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]); 574 613 ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen ); 575 HeapFree( GetProcessHeap(), 0, upcase );614 RtlFreeHeap( GetProcessHeap(), 0, upcase ); 576 615 return ret; 577 616 } … … 588 627 DWORD i; 589 628 590 if (!(upcase = HeapAlloc( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;629 if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY; 591 630 for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]); 592 631 ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen ); 593 HeapFree( GetProcessHeap(), 0, upcase );632 RtlFreeHeap( GetProcessHeap(), 0, upcase ); 594 633 return ret; 595 634 } … … 602 641 /************************************************************************** 603 642 * RtlOemStringToUnicodeSize (NTDLL.@) 643 * RtlxOemStringToUnicodeSize (NTDLL.@) 604 644 * 605 645 * Return the size in bytes necessary for the Unicode conversion of 'str', … … 608 648 UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str ) 609 649 { 610 DWORD ret = MultiByteToWideChar( CP_OEMCP, 0, str->Buffer, str->Length, NULL, 0 );650 int ret = cp_mbstowcs( get_oem_table(), 0, str->Buffer, str->Length, NULL, 0 ); 611 651 return (ret + 1) * sizeof(WCHAR); 612 652 } … … 615 655 /************************************************************************** 616 656 * RtlAnsiStringToUnicodeSize (NTDLL.@) 657 * RtlxAnsiStringToUnicodeSize (NTDLL.@) 617 658 * 618 659 * Return the size in bytes necessary for the Unicode conversion of 'str', … … 621 662 DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str ) 622 663 { 623 DWORD ret = MultiByteToWideChar( CP_ACP, 0, str->Buffer, str->Length, NULL, 0 ); 624 return (ret + 1) * sizeof(WCHAR); 664 DWORD ret; 665 RtlMultiByteToUnicodeSize( &ret, str->Buffer, str->Length ); 666 return ret + sizeof(WCHAR); 625 667 } 626 668 … … 634 676 NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len ) 635 677 { 636 *size = MultiByteToWideChar( CP_ACP, 0, str, len, NULL, 0 ) * sizeof(WCHAR);637 return 0;678 *size = cp_mbstowcs( get_ansi_table(), 0, str, len, NULL, 0 ) * sizeof(WCHAR); 679 return STATUS_SUCCESS; 638 680 } 639 681 … … 647 689 NTSTATUS WINAPI RtlUnicodeToMultiByteSize( DWORD *size, LPCWSTR str, UINT len ) 648 690 { 649 *size = WideCharToMultiByte( CP_ACP, 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL );650 return 0;691 *size = cp_wcstombs( get_ansi_table(), 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL ); 692 return STATUS_SUCCESS; 651 693 } 652 694 … … 654 696 /************************************************************************** 655 697 * RtlUnicodeStringToAnsiSize (NTDLL.@) 698 * RtlxUnicodeStringToAnsiSize (NTDLL.@) 656 699 * 657 700 * Return the size in bytes necessary for the Ansi conversion of 'str', … … 660 703 DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str ) 661 704 { 662 return WideCharToMultiByte( CP_ACP, 0, str->Buffer, str->Length / sizeof(WCHAR), 663 NULL, 0, NULL, NULL ) + 1; 705 DWORD ret; 706 RtlUnicodeToMultiByteSize( &ret, str->Buffer, str->Length ); 707 return ret + 1; 664 708 } 665 709 … … 667 711 /************************************************************************** 668 712 * RtlUnicodeStringToOemSize (NTDLL.@) 713 * RtlxUnicodeStringToOemSize (NTDLL.@) 669 714 * 670 715 * Return the size in bytes necessary for the OEM conversion of 'str', … … 673 718 DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str ) 674 719 { 675 return WideCharToMultiByte( CP_OEMCP, 0, str->Buffer, str->Length / sizeof(WCHAR),676 720 return cp_wcstombs( get_oem_table(), 0, str->Buffer, str->Length / sizeof(WCHAR), 721 NULL, 0, NULL, NULL ) + 1; 677 722 } 678 723 … … 747 792 748 793 /************************************************************************** 749 * RtlIsTextUnicode 794 * RtlIsTextUnicode (NTDLL.@) 750 795 * 751 796 * Apply various feeble heuristics to guess whether … … 791 836 return len; 792 837 } 793 794 795 /*796 * WIN32OS2 code:797 */798 799 /**800 * Converts an unsigned (long) integer value to a zero terminated unicode string.801 * Hence unicode version of _ultoa.802 * @returns STATUS_SUCCESS on success.803 * STATUS_INVALID_PARAMETER or STATUS_BUFFER_OVERFLOW on error.804 * @param Value The value to convert.805 * @param Base Base number. (2, 8, 10, or 16)806 * @param String Pointer to output buffer.807 * @status completely implemented.808 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)809 * @remark According to docs call must be running at IRQL = PASSIVE_LEVEL...810 */811 NTSTATUS WINAPI RtlIntegerToUnicodeString(812 IN ULONG Value,813 IN ULONG Base OPTIONAL,814 IN OUT PUNICODE_STRING String815 )816 {817 NTSTATUS rc = STATUS_SUCCESS;818 char szBuffer[32+1];819 820 if (Base == 2 || Base == 8 || Base == 10 && Base == 16)821 {822 _ltoa(Value, &szBuffer[0], Base);823 AsciiToUnicode(&szBuffer[0], (unsigned short*)String);824 }825 else826 {827 rc = STATUS_INVALID_PARAMETER;828 }829 830 return rc;831 }832
Note:
See TracChangeset
for help on using the changeset viewer.