- Timestamp:
- May 16, 2002, 2:22:14 PM (23 years ago)
- Location:
- trunk/src/NTDLL
- Files:
-
- 2 added
- 3 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/NTDLL/misc.c
r8428 r8429 34 34 #endif 35 35 36 #ifdef DEBUG 36 37 void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *oa) 37 38 { … … 47 48 return debugstr_wn(us->Buffer, us->Length); 48 49 } 50 #endif 49 51 50 52 /********************************************************************* -
trunk/src/NTDLL/ntdll_misc.h
r5568 r8429 8 8 extern LPCSTR debugstr_as( const STRING *str ); 9 9 extern LPCSTR debugstr_us( const UNICODE_STRING *str ); 10 11 #ifdef DEBUG 10 12 extern void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *ObjectAttributes); 13 #else 14 #define dump_ObjectAttributes(a) 15 #endif 16 11 17 extern void dump_UnicodeString(const UNICODE_STRING *us, BOOLEAN showstring); 12 18 -
trunk/src/NTDLL/reg.cpp
r4059 r8429 1 /* $Id: reg.cpp,v 1. 4 2000-08-20 15:16:58 phallerExp $ */1 /* $Id: reg.cpp,v 1.5 2002-05-16 12:16:47 sandervl Exp $ */ 2 2 3 3 /* … … 432 432 return 0; 433 433 } 434 -
trunk/src/NTDLL/rtl.cpp
r7983 r8429 1 /* $Id: rtl.cpp,v 1.1 4 2002-02-21 22:52:42sandervl Exp $ */1 /* $Id: rtl.cpp,v 1.15 2002-05-16 12:16:47 sandervl Exp $ */ 2 2 3 3 /* … … 270 270 */ 271 271 272 /******************************************************************************273 * RtlCreateHeap [NTDLL]274 */275 HANDLE WINAPI RtlCreateHeap(ULONG Flags,276 PVOID BaseAddress,277 ULONG SizeToReserve,278 ULONG SizeToCommit,279 PVOID Unknown,280 PRTL_HEAP_DEFINITION Definition)281 {282 dprintf(("NTDLL: RtlCreateHeap(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh).\n",283 Flags,284 BaseAddress,285 SizeToReserve,286 SizeToCommit,287 Unknown,288 Definition));289 290 return HeapCreate(Flags,291 SizeToCommit,292 SizeToReserve);293 }294 295 296 /******************************************************************************297 * RtlAllocateHeap [NTDLL]298 */299 PVOID WINAPI RtlAllocateHeap(HANDLE Heap,300 ULONG Flags,301 ULONG Size)302 {303 dprintf(("NTDLL: RtlAllocateHeap(%08xh,%08xh,%08xh).\n",304 Heap,305 Flags,306 Size));307 308 return HeapAlloc(Heap,309 Flags,310 Size);311 }312 313 314 /******************************************************************************315 * RtlFreeHeap [NTDLL]316 */317 BOOLEAN WINAPI RtlFreeHeap(HANDLE Heap,318 ULONG Flags,319 PVOID Address)320 {321 dprintf(("NTDLL: RtlFreeHeap(%08xh,%08xh,%08xh)\n",322 Heap,323 Flags,324 Address));325 326 return HeapFree(Heap, Flags, Address);327 }328 329 330 /******************************************************************************331 * RtlDestroyHeap [NTDLL]332 *333 * FIXME: prototype guessed334 */335 HANDLE WINAPI RtlDestroyHeap( HANDLE Heap )336 {337 dprintf(("NTDLL: RtlDestroyHeap(%08xh)\n",338 Heap));339 340 return HeapDestroy(Heap);341 }342 343 344 345 /******************************************************************************346 * RtlSizeHeap [NTDLL]347 */348 349 ODINFUNCTION3(DWORD,RtlSizeHeap,HANDLE,hHeap,350 DWORD, dwFlags,351 PVOID, pAddress)352 {353 return HeapSize(hHeap,354 dwFlags,355 pAddress);356 }357 358 272 359 273 … … 464 378 } 465 379 466 467 /**************************************************************************468 * RtlNtStatusToDosError [NTDLL.442]469 */470 DWORD WINAPI RtlNtStatusToDosError(DWORD error)471 {472 dprintf(("NTDLL: RtlNtStatusToDosError(%08xh) partially implemented.\n",473 error));474 475 switch (error)476 {477 case STATUS_SUCCESS: return ERROR_SUCCESS;478 case STATUS_INVALID_PARAMETER: return ERROR_BAD_ARGUMENTS;479 case STATUS_BUFFER_TOO_SMALL: return ERROR_INSUFFICIENT_BUFFER;480 /* case STATUS_INVALID_SECURITY_DESCR: return ERROR_INVALID_SECURITY_DESCR;*/481 case STATUS_NO_MEMORY: return ERROR_NOT_ENOUGH_MEMORY;482 /* case STATUS_UNKNOWN_REVISION:483 case STATUS_BUFFER_OVERFLOW:*/484 }485 486 dprintf(("NTDLL: RtlNtStatusToDosError(%08xh is unknown !)\n",487 error));488 489 return ERROR_SUCCESS;490 }491 380 492 381 -
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 -
trunk/src/NTDLL/unknown.cpp
r6712 r8429 1 /* $Id: unknown.cpp,v 1.1 0 2001-09-15 09:36:50sandervl Exp $ */1 /* $Id: unknown.cpp,v 1.11 2002-05-16 12:16:48 sandervl Exp $ */ 2 2 3 3 /* -
trunk/src/NTDLL/wcstring.c
r7343 r8429 4 4 * Copyright 2000 Alexandre Julliard 5 5 * Copyright 2000 Jon Griffiths 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 … … 14 28 #include <stdio.h> 15 29 16 #ifdef __WIN32OS2__ 17 #include <stdarg.h> 18 #include <heapstring.h> 19 #endif 20 21 #include "windef.h" 22 #include "winbase.h" 23 #include "winnls.h" 30 #include "ntddk.h" 24 31 #include "wine/unicode.h" 25 #include "heap.h" 26 #include "debugtools.h" 27 28 DEFAULT_DEBUG_CHANNEL(ntdll); 32 #include "wine/debug.h" 33 34 WINE_DEFAULT_DEBUG_CHANNEL(ntdll); 29 35 30 36 … … 258 264 INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n ) 259 265 { 260 INT ret; 261 if (n <= 0) return 0; 262 ret = WideCharToMultiByte( CP_ACP, 0, src, -1, dst, dst ? n : 0, NULL, NULL ); 263 if (!ret) return n; /* overflow */ 264 return ret - 1; /* do not count terminating NULL */ 266 DWORD len; 267 268 if (!dst) 269 { 270 RtlUnicodeToMultiByteSize( &len, src, strlenW(src)*sizeof(WCHAR) ); 271 return len; 272 } 273 else 274 { 275 if (n <= 0) return 0; 276 RtlUnicodeToMultiByteN( dst, n, &len, src, strlenW(src)*sizeof(WCHAR) ); 277 if (len < n) dst[len] = 0; 278 } 279 return len; 265 280 } 266 281 … … 271 286 INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n ) 272 287 { 273 INT ret; 274 if (n <= 0) return 0; 275 ret = MultiByteToWideChar( CP_ACP, 0, src, -1, dst, dst ? n : 0 ); 276 if (!ret) return n; /* overflow */ 277 return ret - 1; /* do not count terminating NULL */ 288 DWORD len; 289 290 if (!dst) 291 { 292 RtlMultiByteToUnicodeSize( &len, src, strlen(src) ); 293 } 294 else 295 { 296 if (n <= 0) return 0; 297 RtlMultiByteToUnicodeN( dst, n*sizeof(WCHAR), &len, src, strlen(src) ); 298 if (len / sizeof(WCHAR) < n) dst[len / sizeof(WCHAR)] = 0; 299 } 300 return len / sizeof(WCHAR); 278 301 } 279 302 … … 283 306 * Like strtol, but for wide character strings. 284 307 */ 285 INT __cdecl NTDLL_wcstol(LPWSTR s,LPWSTR *end,INT base) 286 { 287 LPSTR sA = HEAP_strdupWtoA(GetProcessHeap(),0,s),endA; 288 INT ret = strtol(sA,&endA,base); 289 290 HeapFree(GetProcessHeap(),0,sA); 291 if (end) *end = s+(endA-sA); /* pointer magic checked. */ 308 INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base) 309 { 310 UNICODE_STRING uni; 311 ANSI_STRING ansi; 312 INT ret; 313 LPSTR endA; 314 315 RtlInitUnicodeString( &uni, s ); 316 RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE ); 317 ret = strtol( ansi.Buffer, &endA, base ); 318 if (end) 319 { 320 DWORD len; 321 RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer ); 322 *end = (LPWSTR)s + len/sizeof(WCHAR); 323 } 324 RtlFreeAnsiString( &ansi ); 325 return ret; 326 } 327 328 329 /********************************************************************* 330 * wcstoul (NTDLL.@) 331 * Like strtoul, but for wide character strings. 332 */ 333 INT __cdecl NTDLL_wcstoul(LPCWSTR s,LPWSTR *end,INT base) 334 { 335 UNICODE_STRING uni; 336 ANSI_STRING ansi; 337 INT ret; 338 LPSTR endA; 339 340 RtlInitUnicodeString( &uni, s ); 341 RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE ); 342 ret = strtoul( ansi.Buffer, &endA, base ); 343 if (end) 344 { 345 DWORD len; 346 RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer ); 347 *end = (LPWSTR)s + len/sizeof(WCHAR); 348 } 349 RtlFreeAnsiString( &ansi ); 292 350 return ret; 293 351 }
Note:
See TracChangeset
for help on using the changeset viewer.