Commit 996c0bff authored by Alexandre Julliard's avatar Alexandre Julliard

Removed ntdll dependency on MultiByteToWideChar/WideCharToMultiByte

kernel32 functions, plus a few small cleanups.
parent 63d13317
......@@ -25,23 +25,6 @@ void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *oa)
oa->Attributes, oa->RootDirectory, oa->SecurityDescriptor);
}
void dump_UnicodeString(const UNICODE_STRING *us, BOOLEAN showstring)
{
if (us)
{
if (showstring)
TRACE("%p %p(%s) (%u %u)\n", us, us->Buffer, debugstr_us(us), us->Length, us->MaximumLength);
else
TRACE("%p %p(<OUT>) (%u %u)\n", us, us->Buffer, us->Length, us->MaximumLength);
}
}
LPCSTR debugstr_as( const STRING *str )
{
if (!str) return "<null>";
return debugstr_an(str->Buffer, str->Length);
}
LPCSTR debugstr_us( const UNICODE_STRING *us )
{
if (!us) return "<null>";
......
......@@ -60,8 +60,9 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stub LdrUnloadDll
@ stub LdrVerifyImageMatchesChecksum
@ stub NPXEMULATORTABLE
@ stub NlsMbCodePageTag
@ stub NlsMbOemCodePageTag
@ extern NlsAnsiCodePage NlsAnsiCodePage
@ extern NlsMbCodePageTag NlsMbCodePageTag
@ extern NlsMbOemCodePageTag NlsMbOemCodePageTag
@ stdcall NtAcceptConnectPort(long long long long long long) NtAcceptConnectPort
@ stdcall NtAccessCheck(ptr long long ptr ptr ptr ptr ptr) NtAccessCheck
@ stub NtAccessCheckAndAuditAlarm
......@@ -1034,3 +1035,6 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
# Server interface
@ cdecl -norelay wine_server_call(ptr) wine_server_call
# Codepages
@ cdecl __wine_init_codepages(ptr ptr) __wine_init_codepages
......@@ -5,9 +5,7 @@
#include "winnt.h"
/* debug helper */
extern LPCSTR debugstr_as( const STRING *str );
extern LPCSTR debugstr_us( const UNICODE_STRING *str );
extern void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *ObjectAttributes);
extern void dump_UnicodeString(const UNICODE_STRING *us, BOOLEAN showstring);
#endif
......@@ -261,14 +261,13 @@ BOOLEAN WINAPI RtlFreeHeap(
/******************************************************************************
* RtlDestroyHeap [NTDLL.@]
*
* FIXME: prototype guessed
*/
BOOLEAN WINAPI RtlDestroyHeap(
HANDLE WINAPI RtlDestroyHeap(
HANDLE Heap)
{
TRACE("(0x%08x) semi stub\n", Heap);
return HeapDestroy(Heap);
if (!HeapDestroy(Heap)) return Heap;
return 0;
}
/*
......
......@@ -56,7 +56,7 @@ BOOLEAN WINAPI RtlAllocateAndInitializeSid (
nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, pSid);
if (!(*pSid = HeapAlloc( GetProcessHeap(), 0, RtlLengthRequiredSid(nSubAuthorityCount))))
if (!(*pSid = RtlAllocateHeap( GetProcessHeap(), 0, RtlLengthRequiredSid(nSubAuthorityCount))))
return FALSE;
(*pSid)->Revision = SID_REVISION;
......@@ -126,7 +126,7 @@ BOOL WINAPI RtlEqualPrefixSid (PSID pSid1, PSID pSid2)
DWORD WINAPI RtlFreeSid(PSID pSid)
{
TRACE("(%p)\n", pSid);
HeapFree( GetProcessHeap(), 0, pSid );
RtlFreeHeap( GetProcessHeap(), 0, pSid );
return STATUS_SUCCESS;
}
......@@ -719,7 +719,9 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString(
ANSI_STRING AnsiStr;
FIXME("(%p %p)\n", UnicodeSID, pSid);
dump_UnicodeString(UnicodeSID, FALSE);
if (UnicodeSID)
TRACE("%p(<OUT>) (%u %u)\n",
UnicodeSID->Buffer, UnicodeSID->Length, UnicodeSID->MaximumLength);
RtlInitAnsiString(&AnsiStr, GenSID);
return RtlAnsiStringToUnicodeString(UnicodeSID, &AnsiStr, TRUE);
......
......@@ -13,11 +13,8 @@
#include <string.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "ntddk.h"
#include "wine/unicode.h"
#include "heap.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(ntdll);
......@@ -252,11 +249,20 @@ LPWSTR __cdecl NTDLL_wcstok( LPWSTR str, LPCWSTR delim )
*/
INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n )
{
INT ret;
if (n <= 0) return 0;
ret = WideCharToMultiByte( CP_ACP, 0, src, -1, dst, dst ? n : 0, NULL, NULL );
if (!ret) return n; /* overflow */
return ret - 1; /* do not count terminating NULL */
DWORD len;
if (!dst)
{
RtlUnicodeToMultiByteSize( &len, src, strlenW(src)*sizeof(WCHAR) );
return len;
}
else
{
if (n <= 0) return 0;
RtlUnicodeToMultiByteN( dst, n, &len, src, strlenW(src)*sizeof(WCHAR) );
if (len < n) dst[len] = 0;
}
return len;
}
......@@ -265,11 +271,19 @@ INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n )
*/
INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
{
INT ret;
if (n <= 0) return 0;
ret = MultiByteToWideChar( CP_ACP, 0, src, -1, dst, dst ? n : 0 );
if (!ret) return n; /* overflow */
return ret - 1; /* do not count terminating NULL */
DWORD len;
if (!dst)
{
RtlMultiByteToUnicodeSize( &len, src, strlen(src) );
}
else
{
if (n <= 0) return 0;
RtlMultiByteToUnicodeN( dst, n*sizeof(WCHAR), &len, src, strlen(src) );
if (len / sizeof(WCHAR) < n) dst[len / sizeof(WCHAR)] = 0;
}
return len / sizeof(WCHAR);
}
......@@ -279,11 +293,21 @@ INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
*/
INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base)
{
LPSTR sA = HEAP_strdupWtoA(GetProcessHeap(),0,s),endA;
INT ret = strtol(sA,&endA,base);
UNICODE_STRING uni;
ANSI_STRING ansi;
INT ret;
LPSTR endA;
HeapFree(GetProcessHeap(),0,sA);
if (end) *end = ((LPWSTR)s)+(endA-sA); /* pointer magic checked. */
RtlInitUnicodeString( &uni, s );
RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE );
ret = strtol( ansi.Buffer, &endA, base );
if (end)
{
DWORD len;
RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer );
*end = (LPWSTR)s + len/sizeof(WCHAR);
}
RtlFreeAnsiString( &ansi );
return ret;
}
......@@ -294,11 +318,21 @@ INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base)
*/
INT __cdecl NTDLL_wcstoul(LPCWSTR s,LPWSTR *end,INT base)
{
LPSTR sA = HEAP_strdupWtoA(GetProcessHeap(),0,s),endA;
INT ret = strtoul(sA,&endA,base);
UNICODE_STRING uni;
ANSI_STRING ansi;
INT ret;
LPSTR endA;
HeapFree(GetProcessHeap(),0,sA);
if (end) *end = ((LPWSTR)s)+(endA-sA); /* pointer magic checked. */
RtlInitUnicodeString( &uni, s );
RtlUnicodeStringToAnsiString( &ansi, &uni, TRUE );
ret = strtoul( ansi.Buffer, &endA, base );
if (end)
{
DWORD len;
RtlMultiByteToUnicodeSize( &len, ansi.Buffer, endA - ansi.Buffer );
*end = (LPWSTR)s + len/sizeof(WCHAR);
}
RtlFreeAnsiString( &ansi );
return ret;
}
......
......@@ -583,7 +583,7 @@ DWORD WINAPI RtlGetAce(
/* string functions */
DWORD WINAPI RtlAnsiStringToUnicodeSize(PSTRING);
DWORD WINAPI RtlAnsiStringToUnicodeSize(const STRING*);
NTSTATUS WINAPI RtlAnsiStringToUnicodeString(UNICODE_STRING*,const STRING *,BOOLEAN);
NTSTATUS WINAPI RtlAppendAsciizToString(STRING*,LPCSTR);
NTSTATUS WINAPI RtlAppendStringToString(STRING*,const STRING*);
......@@ -606,7 +606,7 @@ void WINAPI RtlInitString(PSTRING,LPCSTR);
void WINAPI RtlInitUnicodeString(PUNICODE_STRING,LPCWSTR);
NTSTATUS WINAPI RtlMultiByteToUnicodeN(LPWSTR,DWORD,LPDWORD,LPCSTR,DWORD);
NTSTATUS WINAPI RtlMultiByteToUnicodeSize(DWORD*,LPCSTR,UINT);
UINT WINAPI RtlOemStringToUnicodeSize(PSTRING);
UINT WINAPI RtlOemStringToUnicodeSize(const STRING*);
NTSTATUS WINAPI RtlOemStringToUnicodeString(UNICODE_STRING*,const STRING*,BOOLEAN);
NTSTATUS WINAPI RtlOemToUnicodeN(LPWSTR,DWORD,LPDWORD,LPCSTR,DWORD);
BOOLEAN WINAPI RtlPrefixString(const STRING*,const STRING*,BOOLEAN);
......@@ -712,24 +712,17 @@ typedef struct
ULONG Unknown[11];
} RTL_HEAP_DEFINITION, *PRTL_HEAP_DEFINITION;
HANDLE WINAPI RtlCreateHeap(
ULONG Flags,
PVOID BaseAddress,
ULONG SizeToReserve,
ULONG SizeToCommit,
PVOID Unknown,
PRTL_HEAP_DEFINITION Definition);
PVOID WINAPI RtlAllocateHeap(
HANDLE Heap,
ULONG Flags,
ULONG Size);
BOOLEAN WINAPI RtlFreeHeap(
HANDLE Heap,
ULONG Flags,
PVOID Address);
HANDLE WINAPI RtlCreateHeap(ULONG,PVOID,ULONG,ULONG,PVOID,PRTL_HEAP_DEFINITION);
HANDLE WINAPI RtlDestroyHeap(HANDLE);
PVOID WINAPI RtlAllocateHeap(HANDLE,ULONG,ULONG);
BOOLEAN WINAPI RtlFreeHeap(HANDLE,ULONG,PVOID);
PVOID WINAPI RtlReAllocateHeap(HANDLE,ULONG,PVOID,ULONG);
ULONG WINAPI RtlCompactHeap(HANDLE,ULONG);
BOOLEAN WINAPI RtlLockHeap(HANDLE);
BOOLEAN WINAPI RtlUnlockHeap(HANDLE);
ULONG WINAPI RtlSizeHeap(HANDLE,ULONG,PVOID);
BOOLEAN WINAPI RtlValidateHeap(HANDLE,ULONG,PCVOID);
ULONG WINAPI RtlGetProcessHeaps(ULONG,HANDLE*);
/* exception */
......
......@@ -74,14 +74,16 @@ static const union cptable *get_codepage_table( unsigned int codepage )
/* since it needs KERNEL32 to be loaded for the locale info. */
void CODEPAGE_Init(void)
{
extern void __wine_init_codepages( const union cptable *ansi, const union cptable *oem );
const union cptable *table;
LCID lcid = GetUserDefaultLCID();
if (!ansi_cptable) init_codepages(); /* just in case */
if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTANSICODEPAGE ))) ansi_cptable = table;
if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTMACCODEPAGE ))) mac_cptable = table;
if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTCODEPAGE ))) oem_cptable = table;
__wine_init_codepages( ansi_cptable, oem_cptable );
TRACE( "ansi=%03d oem=%03d mac=%03d\n", ansi_cptable->info.codepage,
oem_cptable->info.codepage, mac_cptable->info.codepage );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment