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) ...@@ -25,23 +25,6 @@ void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *oa)
oa->Attributes, oa->RootDirectory, oa->SecurityDescriptor); 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 ) LPCSTR debugstr_us( const UNICODE_STRING *us )
{ {
if (!us) return "<null>"; if (!us) return "<null>";
......
...@@ -60,8 +60,9 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup ...@@ -60,8 +60,9 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
@ stub LdrUnloadDll @ stub LdrUnloadDll
@ stub LdrVerifyImageMatchesChecksum @ stub LdrVerifyImageMatchesChecksum
@ stub NPXEMULATORTABLE @ stub NPXEMULATORTABLE
@ stub NlsMbCodePageTag @ extern NlsAnsiCodePage NlsAnsiCodePage
@ stub NlsMbOemCodePageTag @ extern NlsMbCodePageTag NlsMbCodePageTag
@ extern NlsMbOemCodePageTag NlsMbOemCodePageTag
@ stdcall NtAcceptConnectPort(long long long long long long) NtAcceptConnectPort @ stdcall NtAcceptConnectPort(long long long long long long) NtAcceptConnectPort
@ stdcall NtAccessCheck(ptr long long ptr ptr ptr ptr ptr) NtAccessCheck @ stdcall NtAccessCheck(ptr long long ptr ptr ptr ptr ptr) NtAccessCheck
@ stub NtAccessCheckAndAuditAlarm @ stub NtAccessCheckAndAuditAlarm
...@@ -1034,3 +1035,6 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup ...@@ -1034,3 +1035,6 @@ debug_channels (atom cdrom console debug delayhlp dll dosfs dosmem file fixup
# Server interface # Server interface
@ cdecl -norelay wine_server_call(ptr) wine_server_call @ cdecl -norelay wine_server_call(ptr) wine_server_call
# Codepages
@ cdecl __wine_init_codepages(ptr ptr) __wine_init_codepages
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
#include "winnt.h" #include "winnt.h"
/* debug helper */ /* debug helper */
extern LPCSTR debugstr_as( const STRING *str );
extern LPCSTR debugstr_us( const UNICODE_STRING *str ); extern LPCSTR debugstr_us( const UNICODE_STRING *str );
extern void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *ObjectAttributes); extern void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *ObjectAttributes);
extern void dump_UnicodeString(const UNICODE_STRING *us, BOOLEAN showstring);
#endif #endif
...@@ -261,14 +261,13 @@ BOOLEAN WINAPI RtlFreeHeap( ...@@ -261,14 +261,13 @@ BOOLEAN WINAPI RtlFreeHeap(
/****************************************************************************** /******************************************************************************
* RtlDestroyHeap [NTDLL.@] * RtlDestroyHeap [NTDLL.@]
*
* FIXME: prototype guessed
*/ */
BOOLEAN WINAPI RtlDestroyHeap( HANDLE WINAPI RtlDestroyHeap(
HANDLE Heap) HANDLE Heap)
{ {
TRACE("(0x%08x) semi stub\n", Heap); TRACE("(0x%08x) semi stub\n", Heap);
return HeapDestroy(Heap); if (!HeapDestroy(Heap)) return Heap;
return 0;
} }
/* /*
......
...@@ -7,18 +7,49 @@ ...@@ -7,18 +7,49 @@
#include "config.h" #include "config.h"
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "ntddk.h"
#include "wine/unicode.h" #include "wine/unicode.h"
#include "winnls.h"
#include "debugtools.h" #include "debugtools.h"
#include "ntdll_misc.h"
#include "ntddk.h"
DEFAULT_DEBUG_CHANNEL(ntdll); DEFAULT_DEBUG_CHANNEL(ntdll);
/* STRING CREATION FUNCTIONS */ UINT NlsAnsiCodePage = 1252;
BYTE NlsMbCodePageTag = 0;
BYTE NlsMbOemCodePageTag = 0;
static const union cptable *ansi_table;
static const union cptable *oem_table;
inline static const union cptable *get_ansi_table(void)
{
if (!ansi_table) ansi_table = cp_get_table( 1252 );
return ansi_table;
}
inline static const union cptable *get_oem_table(void)
{
if (!oem_table) oem_table = cp_get_table( 437 );
return oem_table;
}
/**************************************************************************
* __wine_init_codepages (NTDLL.@)
*
* Set the code page once kernel32 is loaded. Should be done differently.
*/
void __wine_init_codepages( const union cptable *ansi, const union cptable *oem )
{
ansi_table = ansi;
oem_table = oem;
NlsAnsiCodePage = ansi->info.codepage;
}
/************************************************************************** /**************************************************************************
* RtlInitAnsiString (NTDLL.@) * RtlInitAnsiString (NTDLL.@)
...@@ -48,7 +79,7 @@ void WINAPI RtlInitString( PSTRING target, LPCSTR source ) ...@@ -48,7 +79,7 @@ void WINAPI RtlInitString( PSTRING target, LPCSTR source )
*/ */
void WINAPI RtlFreeAnsiString( PSTRING str ) void WINAPI RtlFreeAnsiString( PSTRING str )
{ {
if (str->Buffer) HeapFree( GetProcessHeap(), 0, str->Buffer ); if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
} }
...@@ -96,7 +127,7 @@ void WINAPI RtlInitUnicodeString( PUNICODE_STRING target, LPCWSTR source ) ...@@ -96,7 +127,7 @@ void WINAPI RtlInitUnicodeString( PUNICODE_STRING target, LPCWSTR source )
BOOLEAN WINAPI RtlCreateUnicodeString( PUNICODE_STRING target, LPCWSTR src ) BOOLEAN WINAPI RtlCreateUnicodeString( PUNICODE_STRING target, LPCWSTR src )
{ {
int len = (strlenW(src) + 1) * sizeof(WCHAR); int len = (strlenW(src) + 1) * sizeof(WCHAR);
if (!(target->Buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE; if (!(target->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return FALSE;
memcpy( target->Buffer, src, len ); memcpy( target->Buffer, src, len );
target->MaximumLength = len; target->MaximumLength = len;
target->Length = len - 2; target->Length = len - 2;
...@@ -120,7 +151,7 @@ BOOLEAN WINAPI RtlCreateUnicodeStringFromAsciiz( PUNICODE_STRING target, LPCSTR ...@@ -120,7 +151,7 @@ BOOLEAN WINAPI RtlCreateUnicodeStringFromAsciiz( PUNICODE_STRING target, LPCSTR
*/ */
void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str ) void WINAPI RtlFreeUnicodeString( PUNICODE_STRING str )
{ {
if (str->Buffer) HeapFree( GetProcessHeap(), 0, str->Buffer ); if (str->Buffer) RtlFreeHeap( GetProcessHeap(), 0, str->Buffer );
} }
...@@ -297,20 +328,19 @@ NTSTATUS WINAPI RtlAnsiStringToUnicodeString( UNICODE_STRING *uni, ...@@ -297,20 +328,19 @@ NTSTATUS WINAPI RtlAnsiStringToUnicodeString( UNICODE_STRING *uni,
const STRING *ansi, const STRING *ansi,
BOOLEAN doalloc ) BOOLEAN doalloc )
{ {
DWORD len = MultiByteToWideChar( CP_ACP, 0, ansi->Buffer, ansi->Length, NULL, 0 ); DWORD total = RtlAnsiStringToUnicodeSize( ansi );
DWORD total = (len + 1) * sizeof(WCHAR);
if (total > 0xffff) return STATUS_INVALID_PARAMETER_2; if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
uni->Length = len * sizeof(WCHAR); uni->Length = total - sizeof(WCHAR);
if (doalloc) if (doalloc)
{ {
uni->MaximumLength = total; uni->MaximumLength = total;
if (!(uni->Buffer = HeapAlloc( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY; if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY;
} }
else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW; else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
MultiByteToWideChar( CP_ACP, 0, ansi->Buffer, ansi->Length, uni->Buffer, len ); RtlMultiByteToUnicodeN( uni->Buffer, uni->Length, NULL, ansi->Buffer, ansi->Length );
uni->Buffer[len] = 0; uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -326,20 +356,19 @@ NTSTATUS WINAPI RtlOemStringToUnicodeString( UNICODE_STRING *uni, ...@@ -326,20 +356,19 @@ NTSTATUS WINAPI RtlOemStringToUnicodeString( UNICODE_STRING *uni,
const STRING *oem, const STRING *oem,
BOOLEAN doalloc ) BOOLEAN doalloc )
{ {
DWORD len = MultiByteToWideChar( CP_OEMCP, 0, oem->Buffer, oem->Length, NULL, 0 ); DWORD total = RtlOemStringToUnicodeSize( oem );
DWORD total = (len + 1) * sizeof(WCHAR);
if (total > 0xffff) return STATUS_INVALID_PARAMETER_2; if (total > 0xffff) return STATUS_INVALID_PARAMETER_2;
uni->Length = len * sizeof(WCHAR); uni->Length = total - sizeof(WCHAR);
if (doalloc) if (doalloc)
{ {
uni->MaximumLength = total; uni->MaximumLength = total;
if (!(uni->Buffer = HeapAlloc( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY; if (!(uni->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, total ))) return STATUS_NO_MEMORY;
} }
else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW; else if (total > uni->MaximumLength) return STATUS_BUFFER_OVERFLOW;
MultiByteToWideChar( CP_OEMCP, 0, oem->Buffer, oem->Length, uni->Buffer, len ); RtlOemToUnicodeN( uni->Buffer, uni->Length, NULL, oem->Buffer, oem->Length );
uni->Buffer[len] = 0; uni->Buffer[uni->Length / sizeof(WCHAR)] = 0;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -362,7 +391,7 @@ NTSTATUS WINAPI RtlUnicodeStringToAnsiString( STRING *ansi, ...@@ -362,7 +391,7 @@ NTSTATUS WINAPI RtlUnicodeStringToAnsiString( STRING *ansi,
if (doalloc) if (doalloc)
{ {
ansi->MaximumLength = len + 1; ansi->MaximumLength = len + 1;
if (!(ansi->Buffer = HeapAlloc( GetProcessHeap(), 0, len + 1 ))) return STATUS_NO_MEMORY; if (!(ansi->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len + 1 ))) return STATUS_NO_MEMORY;
} }
else if (ansi->MaximumLength <= len) else if (ansi->MaximumLength <= len)
{ {
...@@ -371,8 +400,7 @@ NTSTATUS WINAPI RtlUnicodeStringToAnsiString( STRING *ansi, ...@@ -371,8 +400,7 @@ NTSTATUS WINAPI RtlUnicodeStringToAnsiString( STRING *ansi,
ret = STATUS_BUFFER_OVERFLOW; ret = STATUS_BUFFER_OVERFLOW;
} }
WideCharToMultiByte( CP_ACP, 0, uni->Buffer, uni->Length / sizeof(WCHAR), RtlUnicodeToMultiByteN( ansi->Buffer, ansi->Length, NULL, uni->Buffer, uni->Length );
ansi->Buffer, ansi->Length, NULL, NULL );
ansi->Buffer[ansi->Length] = 0; ansi->Buffer[ansi->Length] = 0;
return ret; return ret;
} }
...@@ -396,7 +424,7 @@ NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem, ...@@ -396,7 +424,7 @@ NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
if (doalloc) if (doalloc)
{ {
oem->MaximumLength = len + 1; oem->MaximumLength = len + 1;
if (!(oem->Buffer = HeapAlloc( GetProcessHeap(), 0, len + 1 ))) return STATUS_NO_MEMORY; if (!(oem->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len + 1 ))) return STATUS_NO_MEMORY;
} }
else if (oem->MaximumLength <= len) else if (oem->MaximumLength <= len)
{ {
...@@ -405,8 +433,7 @@ NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem, ...@@ -405,8 +433,7 @@ NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
ret = STATUS_BUFFER_OVERFLOW; ret = STATUS_BUFFER_OVERFLOW;
} }
WideCharToMultiByte( CP_OEMCP, 0, uni->Buffer, uni->Length / sizeof(WCHAR), RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, uni->Buffer, uni->Length );
oem->Buffer, oem->Length, NULL, NULL );
oem->Buffer[oem->Length] = 0; oem->Buffer[oem->Length] = 0;
return ret; return ret;
} }
...@@ -421,9 +448,10 @@ NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem, ...@@ -421,9 +448,10 @@ NTSTATUS WINAPI RtlUnicodeStringToOemString( STRING *oem,
NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen, NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
LPCSTR src, DWORD srclen ) LPCSTR src, DWORD srclen )
{ {
DWORD res = MultiByteToWideChar( CP_ACP, 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
int ret = cp_mbstowcs( get_ansi_table(), 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
if (reslen) if (reslen)
*reslen = res ? res * sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */ *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -434,9 +462,9 @@ NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen ...@@ -434,9 +462,9 @@ NTSTATUS WINAPI RtlMultiByteToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen
NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen, NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
LPCSTR src, DWORD srclen ) LPCSTR src, DWORD srclen )
{ {
DWORD res = MultiByteToWideChar( CP_OEMCP, 0, src, srclen, dst, dstlen/sizeof(WCHAR) ); int ret = cp_mbstowcs( get_oem_table(), 0, src, srclen, dst, dstlen/sizeof(WCHAR) );
if (reslen) if (reslen)
*reslen = res ? res * sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */ *reslen = (ret >= 0) ? ret*sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -447,10 +475,10 @@ NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen, ...@@ -447,10 +475,10 @@ NTSTATUS WINAPI RtlOemToUnicodeN( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen, NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
LPCWSTR src, DWORD srclen ) LPCWSTR src, DWORD srclen )
{ {
DWORD res = WideCharToMultiByte( CP_ACP, 0, src, srclen/sizeof(WCHAR), int ret = cp_wcstombs( get_ansi_table(), 0, src, srclen / sizeof(WCHAR),
dst, dstlen, NULL, NULL ); dst, dstlen, NULL, NULL );
if (reslen) if (reslen)
*reslen = res ? res * sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */ *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -461,10 +489,10 @@ NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen, ...@@ -461,10 +489,10 @@ NTSTATUS WINAPI RtlUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
NTSTATUS WINAPI RtlUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen, NTSTATUS WINAPI RtlUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
LPCWSTR src, DWORD srclen ) LPCWSTR src, DWORD srclen )
{ {
DWORD res = WideCharToMultiByte( CP_OEMCP, 0, src, srclen/sizeof(WCHAR), int ret = cp_wcstombs( get_oem_table(), 0, src, srclen / sizeof(WCHAR),
dst, dstlen, NULL, NULL ); dst, dstlen, NULL, NULL );
if (reslen) if (reslen)
*reslen = res ? res * sizeof(WCHAR) : dstlen; /* overflow -> we filled up to dstlen */ *reslen = (ret >= 0) ? ret : dstlen; /* overflow -> we filled up to dstlen */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -502,7 +530,7 @@ NTSTATUS WINAPI RtlUpcaseUnicodeString( UNICODE_STRING *dest, ...@@ -502,7 +530,7 @@ NTSTATUS WINAPI RtlUpcaseUnicodeString( UNICODE_STRING *dest,
if (doalloc) if (doalloc)
{ {
dest->MaximumLength = len; dest->MaximumLength = len;
if (!(dest->Buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY; if (!(dest->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, len ))) return STATUS_NO_MEMORY;
} }
else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW; else if (len > dest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
...@@ -566,10 +594,10 @@ NTSTATUS WINAPI RtlUpcaseUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD r ...@@ -566,10 +594,10 @@ NTSTATUS WINAPI RtlUpcaseUnicodeToMultiByteN( LPSTR dst, DWORD dstlen, LPDWORD r
LPWSTR upcase; LPWSTR upcase;
DWORD i; DWORD i;
if (!(upcase = HeapAlloc( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY; if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]); for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen ); ret = RtlUnicodeToMultiByteN( dst, dstlen, reslen, upcase, srclen );
HeapFree( GetProcessHeap(), 0, upcase ); RtlFreeHeap( GetProcessHeap(), 0, upcase );
return ret; return ret;
} }
...@@ -584,10 +612,10 @@ NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen, ...@@ -584,10 +612,10 @@ NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
LPWSTR upcase; LPWSTR upcase;
DWORD i; DWORD i;
if (!(upcase = HeapAlloc( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY; if (!(upcase = RtlAllocateHeap( GetProcessHeap(), 0, srclen ))) return STATUS_NO_MEMORY;
for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]); for (i = 0; i < srclen/sizeof(WCHAR); i++) upcase[i] = toupperW(src[i]);
ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen ); ret = RtlUnicodeToOemN( dst, dstlen, reslen, upcase, srclen );
HeapFree( GetProcessHeap(), 0, upcase ); RtlFreeHeap( GetProcessHeap(), 0, upcase );
return ret; return ret;
} }
...@@ -603,9 +631,9 @@ NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen, ...@@ -603,9 +631,9 @@ NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( LPSTR dst, DWORD dstlen, LPDWORD reslen,
* Return the size in bytes necessary for the Unicode conversion of 'str', * Return the size in bytes necessary for the Unicode conversion of 'str',
* including the terminating NULL. * including the terminating NULL.
*/ */
UINT WINAPI RtlOemStringToUnicodeSize(PSTRING str) UINT WINAPI RtlOemStringToUnicodeSize( const STRING *str )
{ {
DWORD ret = MultiByteToWideChar( CP_OEMCP, 0, str->Buffer, str->Length, NULL, 0 ); int ret = cp_mbstowcs( get_oem_table(), 0, str->Buffer, str->Length, NULL, 0 );
return (ret + 1) * sizeof(WCHAR); return (ret + 1) * sizeof(WCHAR);
} }
...@@ -617,10 +645,11 @@ UINT WINAPI RtlOemStringToUnicodeSize(PSTRING str) ...@@ -617,10 +645,11 @@ UINT WINAPI RtlOemStringToUnicodeSize(PSTRING str)
* Return the size in bytes necessary for the Unicode conversion of 'str', * Return the size in bytes necessary for the Unicode conversion of 'str',
* including the terminating NULL. * including the terminating NULL.
*/ */
DWORD WINAPI RtlAnsiStringToUnicodeSize(PSTRING str) DWORD WINAPI RtlAnsiStringToUnicodeSize( const STRING *str )
{ {
DWORD ret = MultiByteToWideChar( CP_ACP, 0, str->Buffer, str->Length, NULL, 0 ); DWORD ret;
return (ret + 1) * sizeof(WCHAR); RtlMultiByteToUnicodeSize( &ret, str->Buffer, str->Length );
return ret + sizeof(WCHAR);
} }
...@@ -632,8 +661,8 @@ DWORD WINAPI RtlAnsiStringToUnicodeSize(PSTRING str) ...@@ -632,8 +661,8 @@ DWORD WINAPI RtlAnsiStringToUnicodeSize(PSTRING str)
*/ */
NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len ) NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
{ {
*size = MultiByteToWideChar( CP_ACP, 0, str, len, NULL, 0 ) * sizeof(WCHAR); *size = cp_mbstowcs( get_ansi_table(), 0, str, len, NULL, 0 ) * sizeof(WCHAR);
return 0; return STATUS_SUCCESS;
} }
...@@ -645,8 +674,8 @@ NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len ) ...@@ -645,8 +674,8 @@ NTSTATUS WINAPI RtlMultiByteToUnicodeSize( DWORD *size, LPCSTR str, UINT len )
*/ */
NTSTATUS WINAPI RtlUnicodeToMultiByteSize( DWORD *size, LPCWSTR str, UINT len ) NTSTATUS WINAPI RtlUnicodeToMultiByteSize( DWORD *size, LPCWSTR str, UINT len )
{ {
*size = WideCharToMultiByte( CP_ACP, 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL ); *size = cp_wcstombs( get_ansi_table(), 0, str, len / sizeof(WCHAR), NULL, 0, NULL, NULL );
return 0; return STATUS_SUCCESS;
} }
...@@ -659,8 +688,9 @@ NTSTATUS WINAPI RtlUnicodeToMultiByteSize( DWORD *size, LPCWSTR str, UINT len ) ...@@ -659,8 +688,9 @@ NTSTATUS WINAPI RtlUnicodeToMultiByteSize( DWORD *size, LPCWSTR str, UINT len )
*/ */
DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str ) DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
{ {
return WideCharToMultiByte( CP_ACP, 0, str->Buffer, str->Length / sizeof(WCHAR), DWORD ret;
NULL, 0, NULL, NULL ) + 1; RtlUnicodeToMultiByteSize( &ret, str->Buffer, str->Length );
return ret + 1;
} }
...@@ -673,8 +703,8 @@ DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str ) ...@@ -673,8 +703,8 @@ DWORD WINAPI RtlUnicodeStringToAnsiSize( const UNICODE_STRING *str )
*/ */
DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str ) DWORD WINAPI RtlUnicodeStringToOemSize( const UNICODE_STRING *str )
{ {
return WideCharToMultiByte( CP_OEMCP, 0, str->Buffer, str->Length / sizeof(WCHAR), return cp_wcstombs( get_oem_table(), 0, str->Buffer, str->Length / sizeof(WCHAR),
NULL, 0, NULL, NULL ) + 1; NULL, 0, NULL, NULL ) + 1;
} }
......
...@@ -56,7 +56,7 @@ BOOLEAN WINAPI RtlAllocateAndInitializeSid ( ...@@ -56,7 +56,7 @@ BOOLEAN WINAPI RtlAllocateAndInitializeSid (
nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3, nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, pSid); nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, pSid);
if (!(*pSid = HeapAlloc( GetProcessHeap(), 0, RtlLengthRequiredSid(nSubAuthorityCount)))) if (!(*pSid = RtlAllocateHeap( GetProcessHeap(), 0, RtlLengthRequiredSid(nSubAuthorityCount))))
return FALSE; return FALSE;
(*pSid)->Revision = SID_REVISION; (*pSid)->Revision = SID_REVISION;
...@@ -126,7 +126,7 @@ BOOL WINAPI RtlEqualPrefixSid (PSID pSid1, PSID pSid2) ...@@ -126,7 +126,7 @@ BOOL WINAPI RtlEqualPrefixSid (PSID pSid1, PSID pSid2)
DWORD WINAPI RtlFreeSid(PSID pSid) DWORD WINAPI RtlFreeSid(PSID pSid)
{ {
TRACE("(%p)\n", pSid); TRACE("(%p)\n", pSid);
HeapFree( GetProcessHeap(), 0, pSid ); RtlFreeHeap( GetProcessHeap(), 0, pSid );
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -719,7 +719,9 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString( ...@@ -719,7 +719,9 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString(
ANSI_STRING AnsiStr; ANSI_STRING AnsiStr;
FIXME("(%p %p)\n", UnicodeSID, pSid); 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); RtlInitAnsiString(&AnsiStr, GenSID);
return RtlAnsiStringToUnicodeString(UnicodeSID, &AnsiStr, TRUE); return RtlAnsiStringToUnicodeString(UnicodeSID, &AnsiStr, TRUE);
......
...@@ -13,11 +13,8 @@ ...@@ -13,11 +13,8 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "windef.h" #include "ntddk.h"
#include "winbase.h"
#include "winnls.h"
#include "wine/unicode.h" #include "wine/unicode.h"
#include "heap.h"
#include "debugtools.h" #include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(ntdll); DEFAULT_DEBUG_CHANNEL(ntdll);
...@@ -252,11 +249,20 @@ LPWSTR __cdecl NTDLL_wcstok( LPWSTR str, LPCWSTR delim ) ...@@ -252,11 +249,20 @@ LPWSTR __cdecl NTDLL_wcstok( LPWSTR str, LPCWSTR delim )
*/ */
INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n ) INT __cdecl NTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n )
{ {
INT ret; DWORD len;
if (n <= 0) return 0;
ret = WideCharToMultiByte( CP_ACP, 0, src, -1, dst, dst ? n : 0, NULL, NULL ); if (!dst)
if (!ret) return n; /* overflow */ {
return ret - 1; /* do not count terminating NULL */ 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 ) ...@@ -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 __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
{ {
INT ret; DWORD len;
if (n <= 0) return 0;
ret = MultiByteToWideChar( CP_ACP, 0, src, -1, dst, dst ? n : 0 ); if (!dst)
if (!ret) return n; /* overflow */ {
return ret - 1; /* do not count terminating NULL */ 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 ) ...@@ -279,11 +293,21 @@ INT __cdecl NTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
*/ */
INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base) INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base)
{ {
LPSTR sA = HEAP_strdupWtoA(GetProcessHeap(),0,s),endA; UNICODE_STRING uni;
INT ret = strtol(sA,&endA,base); ANSI_STRING ansi;
INT ret;
LPSTR endA;
HeapFree(GetProcessHeap(),0,sA); RtlInitUnicodeString( &uni, s );
if (end) *end = ((LPWSTR)s)+(endA-sA); /* pointer magic checked. */ 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; return ret;
} }
...@@ -294,11 +318,21 @@ INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base) ...@@ -294,11 +318,21 @@ INT __cdecl NTDLL_wcstol(LPCWSTR s,LPWSTR *end,INT base)
*/ */
INT __cdecl NTDLL_wcstoul(LPCWSTR s,LPWSTR *end,INT base) INT __cdecl NTDLL_wcstoul(LPCWSTR s,LPWSTR *end,INT base)
{ {
LPSTR sA = HEAP_strdupWtoA(GetProcessHeap(),0,s),endA; UNICODE_STRING uni;
INT ret = strtoul(sA,&endA,base); ANSI_STRING ansi;
INT ret;
LPSTR endA;
HeapFree(GetProcessHeap(),0,sA); RtlInitUnicodeString( &uni, s );
if (end) *end = ((LPWSTR)s)+(endA-sA); /* pointer magic checked. */ 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; return ret;
} }
......
...@@ -583,7 +583,7 @@ DWORD WINAPI RtlGetAce( ...@@ -583,7 +583,7 @@ DWORD WINAPI RtlGetAce(
/* string functions */ /* string functions */
DWORD WINAPI RtlAnsiStringToUnicodeSize(PSTRING); DWORD WINAPI RtlAnsiStringToUnicodeSize(const STRING*);
NTSTATUS WINAPI RtlAnsiStringToUnicodeString(UNICODE_STRING*,const STRING *,BOOLEAN); NTSTATUS WINAPI RtlAnsiStringToUnicodeString(UNICODE_STRING*,const STRING *,BOOLEAN);
NTSTATUS WINAPI RtlAppendAsciizToString(STRING*,LPCSTR); NTSTATUS WINAPI RtlAppendAsciizToString(STRING*,LPCSTR);
NTSTATUS WINAPI RtlAppendStringToString(STRING*,const STRING*); NTSTATUS WINAPI RtlAppendStringToString(STRING*,const STRING*);
...@@ -606,7 +606,7 @@ void WINAPI RtlInitString(PSTRING,LPCSTR); ...@@ -606,7 +606,7 @@ void WINAPI RtlInitString(PSTRING,LPCSTR);
void WINAPI RtlInitUnicodeString(PUNICODE_STRING,LPCWSTR); void WINAPI RtlInitUnicodeString(PUNICODE_STRING,LPCWSTR);
NTSTATUS WINAPI RtlMultiByteToUnicodeN(LPWSTR,DWORD,LPDWORD,LPCSTR,DWORD); NTSTATUS WINAPI RtlMultiByteToUnicodeN(LPWSTR,DWORD,LPDWORD,LPCSTR,DWORD);
NTSTATUS WINAPI RtlMultiByteToUnicodeSize(DWORD*,LPCSTR,UINT); 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 RtlOemStringToUnicodeString(UNICODE_STRING*,const STRING*,BOOLEAN);
NTSTATUS WINAPI RtlOemToUnicodeN(LPWSTR,DWORD,LPDWORD,LPCSTR,DWORD); NTSTATUS WINAPI RtlOemToUnicodeN(LPWSTR,DWORD,LPDWORD,LPCSTR,DWORD);
BOOLEAN WINAPI RtlPrefixString(const STRING*,const STRING*,BOOLEAN); BOOLEAN WINAPI RtlPrefixString(const STRING*,const STRING*,BOOLEAN);
...@@ -712,24 +712,17 @@ typedef struct ...@@ -712,24 +712,17 @@ typedef struct
ULONG Unknown[11]; ULONG Unknown[11];
} RTL_HEAP_DEFINITION, *PRTL_HEAP_DEFINITION; } RTL_HEAP_DEFINITION, *PRTL_HEAP_DEFINITION;
HANDLE WINAPI RtlCreateHeap( HANDLE WINAPI RtlCreateHeap(ULONG,PVOID,ULONG,ULONG,PVOID,PRTL_HEAP_DEFINITION);
ULONG Flags, HANDLE WINAPI RtlDestroyHeap(HANDLE);
PVOID BaseAddress, PVOID WINAPI RtlAllocateHeap(HANDLE,ULONG,ULONG);
ULONG SizeToReserve, BOOLEAN WINAPI RtlFreeHeap(HANDLE,ULONG,PVOID);
ULONG SizeToCommit, PVOID WINAPI RtlReAllocateHeap(HANDLE,ULONG,PVOID,ULONG);
PVOID Unknown, ULONG WINAPI RtlCompactHeap(HANDLE,ULONG);
PRTL_HEAP_DEFINITION Definition); BOOLEAN WINAPI RtlLockHeap(HANDLE);
BOOLEAN WINAPI RtlUnlockHeap(HANDLE);
PVOID WINAPI RtlAllocateHeap( ULONG WINAPI RtlSizeHeap(HANDLE,ULONG,PVOID);
HANDLE Heap, BOOLEAN WINAPI RtlValidateHeap(HANDLE,ULONG,PCVOID);
ULONG Flags, ULONG WINAPI RtlGetProcessHeaps(ULONG,HANDLE*);
ULONG Size);
BOOLEAN WINAPI RtlFreeHeap(
HANDLE Heap,
ULONG Flags,
PVOID Address);
/* exception */ /* exception */
......
...@@ -74,14 +74,16 @@ static const union cptable *get_codepage_table( unsigned int codepage ) ...@@ -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. */ /* since it needs KERNEL32 to be loaded for the locale info. */
void CODEPAGE_Init(void) void CODEPAGE_Init(void)
{ {
extern void __wine_init_codepages( const union cptable *ansi, const union cptable *oem );
const union cptable *table; const union cptable *table;
LCID lcid = GetUserDefaultLCID(); LCID lcid = GetUserDefaultLCID();
if (!ansi_cptable) init_codepages(); /* just in case */ 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_IDEFAULTANSICODEPAGE ))) ansi_cptable = table;
if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTMACCODEPAGE ))) mac_cptable = table; if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTMACCODEPAGE ))) mac_cptable = table;
if ((table = get_locale_cp( lcid, LOCALE_IDEFAULTCODEPAGE ))) oem_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, TRACE( "ansi=%03d oem=%03d mac=%03d\n", ansi_cptable->info.codepage,
oem_cptable->info.codepage, mac_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