Changeset 8429 for trunk/src


Ignore:
Timestamp:
May 16, 2002, 2:22:14 PM (23 years ago)
Author:
sandervl
Message:

resync with latest wine

Location:
trunk/src/NTDLL
Files:
2 added
3 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/NTDLL/misc.c

    r8428 r8429  
    3434#endif
    3535
     36#ifdef DEBUG
    3637void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *oa)
    3738{
     
    4748    return debugstr_wn(us->Buffer, us->Length);
    4849}
     50#endif
    4951
    5052/*********************************************************************
  • trunk/src/NTDLL/ntdll_misc.h

    r5568 r8429  
    88extern LPCSTR debugstr_as( const STRING *str );
    99extern LPCSTR debugstr_us( const UNICODE_STRING *str );
     10
     11#ifdef DEBUG
    1012extern void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *ObjectAttributes);
     13#else
     14#define dump_ObjectAttributes(a)
     15#endif
     16
    1117extern void dump_UnicodeString(const UNICODE_STRING *us, BOOLEAN showstring);
    1218
  • trunk/src/NTDLL/reg.cpp

    r4059 r8429  
    1 /* $Id: reg.cpp,v 1.4 2000-08-20 15:16:58 phaller Exp $ */
     1/* $Id: reg.cpp,v 1.5 2002-05-16 12:16:47 sandervl Exp $ */
    22
    33/*
     
    432432  return 0;
    433433}
     434
  • trunk/src/NTDLL/rtl.cpp

    r7983 r8429  
    1 /* $Id: rtl.cpp,v 1.14 2002-02-21 22:52:42 sandervl Exp $ */
     1/* $Id: rtl.cpp,v 1.15 2002-05-16 12:16:47 sandervl Exp $ */
    22
    33/*
     
    270270 */
    271271
    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 guessed
    334  */
    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 
    358272
    359273
     
    464378}
    465379
    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 }
    491380
    492381
  • trunk/src/NTDLL/rtlstr.c

    r7983 r8429  
    44 * Copyright (C) 1996-1998 Marcus Meissner
    55 * 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
    620 */
    721
    822#include "config.h"
    923
     24#include <assert.h>
    1025#include <stdlib.h>
    1126#include <string.h>
    1227#include <ctype.h>
     28
     29#include "ntddk.h"
    1330#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
     33WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
     34
     35UINT NlsAnsiCodePage = 1252;
     36BYTE NlsMbCodePageTag = 0;
     37BYTE NlsMbOemCodePageTag = 0;
     38
     39static const union cptable *ansi_table;
     40static const union cptable *oem_table;
     41
     42inline 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
     48inline 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 */
     60void __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
    2467
    2568/**************************************************************************
     
    4285void WINAPI RtlInitString( PSTRING target, LPCSTR source )
    4386{
    44     //return RtlInitAnsiString( target, source ); /* WATCOM: can't return void */
    45     RtlInitAnsiString( target, source );
     87    return RtlInitAnsiString( target, source );
    4688}
    4789
     
    5294void WINAPI RtlFreeAnsiString( PSTRING str )
    5395{
    54     if (str->Buffer) HeapFree( GetProcessHeap(), 0, str->Buffer );
     96    if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
    5597}
    5698
     
    100142{
    101143    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;
    103145    memcpy( target->Buffer, src, len );
    104146    target->MaximumLength = len;
     
    124166void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str )
    125167{
    126     if (str->Buffer) HeapFree( GetProcessHeap(), 0, str->Buffer );
     168    if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
    127169}
    128170
     
    301343                                              BOOLEAN doalloc )
    302344{
    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 );
    305346
    306347    if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
    307     uni->Length = len * sizeof(WCHAR);
     348    uni->Length = total - sizeof(WCHAR);
    308349    if (doalloc)
    309350    {
    310351        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;
    312353    }
    313354    else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
    314355
    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;
    317358    return STATUS_SUCCESS;
    318359}
     
    330371                                             BOOLEAN doalloc )
    331372{
    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 );
    334374
    335375    if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
    336     uni->Length = len * sizeof(WCHAR);
     376    uni->Length = total - sizeof(WCHAR);
    337377    if (doalloc)
    338378    {
    339379        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;
    341381    }
    342382    else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
    343383
    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;
    346386    return STATUS_SUCCESS;
    347387}
     
    362402    DWORD len = RtlUnicodeStringToAnsiSize( uni );
    363403
    364     ansi->Length = len;
     404    ansi->Length = len - 1;
    365405    if (doalloc)
    366406    {
    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)
    371411    {
    372412        if (!ansi->MaximumLength) return STATUS_BUFFER_OVERFLOW;
     
    375415    }
    376416
    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 );
    379418    ansi->Buffer[ansi->Length] = 0;
    380419    return ret;
     
    396435    DWORD len = RtlUnicodeStringToOemSize( uni );
    397436
    398     oem->Length = len;
     437    oem->Length = len - 1;
    399438    if (doalloc)
    400439    {
    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)
    405444    {
    406445        if (!oem->MaximumLength) return STATUS_BUFFER_OVERFLOW;
     
    409448    }
    410449
    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 );
    413451    oem->Buffer[oem->Length] = 0;
    414452    return ret;
     
    425463                                        LPCSTR src, DWORD srclen )
    426464{
    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) );
    428467    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 */
    430469    return STATUS_SUCCESS;
    431470}
     
    438477                                  LPCSTR src, DWORD srclen )
    439478{
    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) );
    441480    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 */
    443482    return STATUS_SUCCESS;
    444483}
     
    451490                                        LPCWSTR src, DWORD srclen )
    452491{
    453     DWORD res = WideCharToMultiByte( CP_ACP, 0, src, srclen/sizeof(WCHAR),
    454                                      dst, dstlen, NULL, NULL );
     492    int ret = cp_wcstombs( get_ansi_table(), 0, src, srclen / sizeof(WCHAR),
     493                           dst, dstlen, NULL, NULL );
    455494    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 */
    457496    return STATUS_SUCCESS;
    458497}
     
    465504                                  LPCWSTR src, DWORD srclen )
    466505{
    467     DWORD res = WideCharToMultiByte( CP_OEMCP, 0, src, srclen/sizeof(WCHAR),
    468                                      dst, dstlen, NULL, NULL );
     506    int ret = cp_wcstombs( get_oem_table(), 0, src, srclen / sizeof(WCHAR),
     507                           dst, dstlen, NULL, NULL );
    469508    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 */
    471510    return STATUS_SUCCESS;
    472511}
     
    506545    {
    507546        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;
    509548    }
    510549    else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
     
    570609    DWORD i;
    571610
    572     if (!(upcase = HeapAlloc( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
     611    if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
    573612    for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
    574613    ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen );
    575     HeapFree( GetProcessHeap(), 0, upcase );
     614    RtlFreeHeap( GetProcessHeap(), 0, upcase );
    576615    return ret;
    577616}
     
    588627    DWORD i;
    589628
    590     if (!(upcase = HeapAlloc( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
     629    if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
    591630    for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
    592631    ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen );
    593     HeapFree( GetProcessHeap(), 0, upcase );
     632    RtlFreeHeap( GetProcessHeap(), 0, upcase );
    594633    return ret;
    595634}
     
    602641/**************************************************************************
    603642 *      RtlOemStringToUnicodeSize   (NTDLL.@)
     643 *      RtlxOemStringToUnicodeSize  (NTDLL.@)
    604644 *
    605645 * Return the size in bytes necessary for the Unicode conversion of 'str',
     
    608648UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str )
    609649{
    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 );
    611651    return (ret + 1) * sizeof(WCHAR);
    612652}
     
    615655/**************************************************************************
    616656 *      RtlAnsiStringToUnicodeSize   (NTDLL.@)
     657 *      RtlxAnsiStringToUnicodeSize  (NTDLL.@)
    617658 *
    618659 * Return the size in bytes necessary for the Unicode conversion of 'str',
     
    621662DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str )
    622663{
    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);
    625667}
    626668
     
    634676NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
    635677{
    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;
    638680}
    639681
     
    647689NTSTATUS WINAPI RtlUnicodeToMultiByteSize( DWORD *size, LPCWSTR str, UINT len )
    648690{
    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;
    651693}
    652694
     
    654696/**************************************************************************
    655697 *      RtlUnicodeStringToAnsiSize   (NTDLL.@)
     698 *      RtlxUnicodeStringToAnsiSize  (NTDLL.@)
    656699 *
    657700 * Return the size in bytes necessary for the Ansi conversion of 'str',
     
    660703DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
    661704{
    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;
    664708}
    665709
     
    667711/**************************************************************************
    668712 *      RtlUnicodeStringToOemSize   (NTDLL.@)
     713 *      RtlxUnicodeStringToOemSize  (NTDLL.@)
    669714 *
    670715 * Return the size in bytes necessary for the OEM conversion of 'str',
     
    673718DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str )
    674719{
    675     return WideCharToMultiByte( CP_OEMCP, 0, str->Buffer, str->Length / sizeof(WCHAR),
    676                                 NULL, 0, NULL, NULL ) + 1;
     720    return cp_wcstombs( get_oem_table(), 0, str->Buffer, str->Length / sizeof(WCHAR),
     721                        NULL, 0, NULL, NULL ) + 1;
    677722}
    678723
     
    747792
    748793/**************************************************************************
    749  *      RtlIsTextUnicode
     794 *      RtlIsTextUnicode (NTDLL.@)
    750795 *
    751796 *      Apply various feeble heuristics to guess whether
     
    791836        return len;
    792837}
    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  String
    815     )
    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     else
    826     {
    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.10 2001-09-15 09:36:50 sandervl Exp $ */
     1/* $Id: unknown.cpp,v 1.11 2002-05-16 12:16:48 sandervl Exp $ */
    22
    33/*
  • trunk/src/NTDLL/wcstring.c

    r7343 r8429  
    44 * Copyright 2000 Alexandre Julliard
    55 * 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
    620 */
    721
     
    1428#include <stdio.h>
    1529
    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"
    2431#include "wine/unicode.h"
    25 #include "heap.h"
    26 #include "debugtools.h"
    27 
    28 DEFAULT_DEBUG_CHANNEL(ntdll);
     32#include "wine/debug.h"
     33
     34WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
    2935
    3036
     
    258264INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n )
    259265{
    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;
    265280}
    266281
     
    271286INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
    272287{
    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);
    278301}
    279302
     
    283306 * Like strtol, but for wide character strings.
    284307 */
    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. */
     308INT __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 */
     333INT __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 );
    292350    return ret;
    293351}
Note: See TracChangeset for help on using the changeset viewer.