Commit 0d33e5e3 authored by Alexandre Julliard's avatar Alexandre Julliard

Added proper support for switching file APIs between ANSI and OEM

codepages. Optimized some of the A->W conversions by using the per-thread Unicode string buffer.
parent eee90c26
......@@ -28,6 +28,7 @@
#include "winbase.h"
#include "winerror.h"
#include "ntstatus.h"
#include "kernel_private.h"
#include "wine/windef16.h"
#include "wine/server.h"
#include "wine/debug.h"
......@@ -40,16 +41,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(file);
HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree,
DWORD dwNotifyFilter )
{
UNICODE_STRING pathW;
HANDLE ret = INVALID_HANDLE_VALUE;
WCHAR *pathW;
if (RtlCreateUnicodeStringFromAsciiz( &pathW, lpPathName ))
{
ret = FindFirstChangeNotificationW( pathW.Buffer, bWatchSubtree, dwNotifyFilter );
RtlFreeUnicodeString( &pathW );
}
else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return ret;
if (!(pathW = FILE_name_AtoW( lpPathName, FALSE ))) return INVALID_HANDLE_VALUE;
return FindFirstChangeNotificationW( pathW, bWatchSubtree, dwNotifyFilter );
}
/****************************************************************************
......
......@@ -60,6 +60,7 @@ typedef struct
BYTE data[8192]; /* directory data */
} FIND_FIRST_INFO;
static BOOL oem_file_apis;
static WINE_EXCEPTION_FILTER(page_fault)
{
......@@ -175,6 +176,88 @@ void FILE_SetDosError(void)
}
/***********************************************************************
* FILE_name_AtoW
*
* Convert a file name to Unicode, taking into account the OEM/Ansi API mode.
*
* If alloc is FALSE uses the TEB static buffer, so it can only be used when
* there is no possibility for the function to do that twice, taking into
* account any called function.
*/
WCHAR *FILE_name_AtoW( LPCSTR name, BOOL alloc )
{
ANSI_STRING str;
UNICODE_STRING strW, *pstrW;
NTSTATUS status;
RtlInitAnsiString( &str, name );
pstrW = alloc ? &strW : &NtCurrentTeb()->StaticUnicodeString;
if (oem_file_apis)
status = RtlOemStringToUnicodeString( pstrW, &str, alloc );
else
status = RtlAnsiStringToUnicodeString( pstrW, &str, alloc );
if (status == STATUS_SUCCESS) return pstrW->Buffer;
if (status == STATUS_BUFFER_OVERFLOW)
SetLastError( ERROR_FILENAME_EXCED_RANGE );
else
SetLastError( RtlNtStatusToDosError(status) );
return NULL;
}
/***********************************************************************
* FILE_name_WtoA
*
* Convert a file name back to OEM/Ansi. Returns number of bytes copied.
*/
DWORD FILE_name_WtoA( LPCWSTR src, INT srclen, LPSTR dest, INT destlen )
{
DWORD ret;
if (srclen < 0) srclen = strlenW( src ) + 1;
if (oem_file_apis)
RtlUnicodeToOemN( dest, destlen, &ret, src, srclen * sizeof(WCHAR) );
else
RtlUnicodeToMultiByteN( dest, destlen, &ret, src, srclen * sizeof(WCHAR) );
return ret;
}
/**************************************************************************
* SetFileApisToOEM (KERNEL32.@)
*/
VOID WINAPI SetFileApisToOEM(void)
{
oem_file_apis = TRUE;
}
/**************************************************************************
* SetFileApisToANSI (KERNEL32.@)
*/
VOID WINAPI SetFileApisToANSI(void)
{
oem_file_apis = FALSE;
}
/******************************************************************************
* AreFileApisANSI (KERNEL32.@)
*
* Determines if file functions are using ANSI
*
* RETURNS
* TRUE: Set of file functions is using ANSI code page
* FALSE: Set of file functions is using OEM code page
*/
BOOL WINAPI AreFileApisANSI(void)
{
return !oem_file_apis;
}
/**************************************************************************
* Operations on file handles *
**************************************************************************/
......@@ -1231,27 +1314,13 @@ HANDLE WINAPI CreateFileW( LPCWSTR filename, DWORD access, DWORD sharing,
* CreateFileA (KERNEL32.@)
*/
HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing,
LPSECURITY_ATTRIBUTES sa, DWORD creation,
DWORD attributes, HANDLE template)
LPSECURITY_ATTRIBUTES sa, DWORD creation,
DWORD attributes, HANDLE template)
{
UNICODE_STRING filenameW;
HANDLE ret = INVALID_HANDLE_VALUE;
WCHAR *nameW;
if (!filename)
{
SetLastError( ERROR_INVALID_PARAMETER );
return INVALID_HANDLE_VALUE;
}
if (RtlCreateUnicodeStringFromAsciiz(&filenameW, filename))
{
ret = CreateFileW(filenameW.Buffer, access, sharing, sa, creation,
attributes, template);
RtlFreeUnicodeString(&filenameW);
}
else
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return ret;
if (!(nameW = FILE_name_AtoW( filename, FALSE ))) return INVALID_HANDLE_VALUE;
return CreateFileW( nameW, access, sharing, sa, creation, attributes, template );
}
......@@ -1279,17 +1348,10 @@ BOOL WINAPI DeleteFileW( LPCWSTR path )
*/
BOOL WINAPI DeleteFileA( LPCSTR path )
{
UNICODE_STRING pathW;
BOOL ret = FALSE;
WCHAR *pathW;
if (RtlCreateUnicodeStringFromAsciiz(&pathW, path))
{
ret = DeleteFileW(pathW.Buffer);
RtlFreeUnicodeString(&pathW);
}
else
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return ret;
if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE;
return DeleteFileW( pathW );
}
......@@ -1555,22 +1617,11 @@ HANDLE WINAPI FindFirstFileExA( LPCSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevel
HANDLE handle;
WIN32_FIND_DATAA *dataA;
WIN32_FIND_DATAW dataW;
UNICODE_STRING pathW;
if (!lpFileName)
{
SetLastError(ERROR_PATH_NOT_FOUND);
return INVALID_HANDLE_VALUE;
}
WCHAR *nameW;
if (!RtlCreateUnicodeStringFromAsciiz(&pathW, lpFileName))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return INVALID_HANDLE_VALUE;
}
if (!(nameW = FILE_name_AtoW( lpFileName, FALSE ))) return INVALID_HANDLE_VALUE;
handle = FindFirstFileExW(pathW.Buffer, fInfoLevelId, &dataW, fSearchOp, lpSearchFilter, dwAdditionalFlags);
RtlFreeUnicodeString(&pathW);
handle = FindFirstFileExW(nameW, fInfoLevelId, &dataW, fSearchOp, lpSearchFilter, dwAdditionalFlags);
if (handle == INVALID_HANDLE_VALUE) return handle;
dataA = (WIN32_FIND_DATAA *) lpFindFileData;
......@@ -1580,10 +1631,9 @@ HANDLE WINAPI FindFirstFileExA( LPCSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevel
dataA->ftLastWriteTime = dataW.ftLastWriteTime;
dataA->nFileSizeHigh = dataW.nFileSizeHigh;
dataA->nFileSizeLow = dataW.nFileSizeLow;
WideCharToMultiByte( CP_ACP, 0, dataW.cFileName, -1,
dataA->cFileName, sizeof(dataA->cFileName), NULL, NULL );
WideCharToMultiByte( CP_ACP, 0, dataW.cAlternateFileName, -1,
dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName), NULL, NULL );
FILE_name_WtoA( dataW.cFileName, -1, dataA->cFileName, sizeof(dataA->cFileName) );
FILE_name_WtoA( dataW.cAlternateFileName, -1, dataA->cAlternateFileName,
sizeof(dataA->cAlternateFileName) );
return handle;
}
......@@ -1612,11 +1662,9 @@ BOOL WINAPI FindNextFileA( HANDLE handle, WIN32_FIND_DATAA *data )
data->ftLastWriteTime = dataW.ftLastWriteTime;
data->nFileSizeHigh = dataW.nFileSizeHigh;
data->nFileSizeLow = dataW.nFileSizeLow;
WideCharToMultiByte( CP_ACP, 0, dataW.cFileName, -1,
data->cFileName, sizeof(data->cFileName), NULL, NULL );
WideCharToMultiByte( CP_ACP, 0, dataW.cAlternateFileName, -1,
data->cAlternateFileName,
sizeof(data->cAlternateFileName), NULL, NULL );
FILE_name_WtoA( dataW.cFileName, -1, data->cFileName, sizeof(data->cFileName) );
FILE_name_WtoA( dataW.cAlternateFileName, -1, data->cAlternateFileName,
sizeof(data->cAlternateFileName) );
return TRUE;
}
......@@ -1662,23 +1710,10 @@ DWORD WINAPI GetFileAttributesW( LPCWSTR name )
*/
DWORD WINAPI GetFileAttributesA( LPCSTR name )
{
UNICODE_STRING nameW;
DWORD ret = INVALID_FILE_ATTRIBUTES;
WCHAR *nameW;
if (!name)
{
SetLastError( ERROR_INVALID_PARAMETER );
return INVALID_FILE_ATTRIBUTES;
}
if (RtlCreateUnicodeStringFromAsciiz(&nameW, name))
{
ret = GetFileAttributesW(nameW.Buffer);
RtlFreeUnicodeString(&nameW);
}
else
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return ret;
if (!(nameW = FILE_name_AtoW( name, FALSE ))) return INVALID_FILE_ATTRIBUTES;
return GetFileAttributesW( nameW );
}
......@@ -1730,23 +1765,10 @@ BOOL WINAPI SetFileAttributesW( LPCWSTR name, DWORD attributes )
*/
BOOL WINAPI SetFileAttributesA( LPCSTR name, DWORD attributes )
{
UNICODE_STRING filenameW;
BOOL ret = FALSE;
WCHAR *nameW;
if (!name)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
if (RtlCreateUnicodeStringFromAsciiz(&filenameW, name))
{
ret = SetFileAttributesW(filenameW.Buffer, attributes);
RtlFreeUnicodeString(&filenameW);
}
else
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return ret;
if (!(nameW = FILE_name_AtoW( name, FALSE ))) return FALSE;
return SetFileAttributesW( nameW, attributes );
}
......@@ -1807,23 +1829,10 @@ BOOL WINAPI GetFileAttributesExW( LPCWSTR name, GET_FILEEX_INFO_LEVELS level, LP
*/
BOOL WINAPI GetFileAttributesExA( LPCSTR name, GET_FILEEX_INFO_LEVELS level, LPVOID ptr )
{
UNICODE_STRING filenameW;
BOOL ret = FALSE;
if (!name)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
WCHAR *nameW;
if (RtlCreateUnicodeStringFromAsciiz(&filenameW, name))
{
ret = GetFileAttributesExW(filenameW.Buffer, level, ptr);
RtlFreeUnicodeString(&filenameW);
}
else
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return ret;
if (!(nameW = FILE_name_AtoW( name, FALSE ))) return FALSE;
return GetFileAttributesExW( nameW, level, ptr );
}
......@@ -1878,20 +1887,10 @@ DWORD WINAPI GetCompressedFileSizeW(
*/
DWORD WINAPI GetCompressedFileSizeA( LPCSTR name, LPDWORD size_high )
{
UNICODE_STRING filenameW;
DWORD ret;
WCHAR *nameW;
if (RtlCreateUnicodeStringFromAsciiz(&filenameW, name))
{
ret = GetCompressedFileSizeW(filenameW.Buffer, size_high);
RtlFreeUnicodeString(&filenameW);
}
else
{
ret = INVALID_FILE_SIZE;
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
}
return ret;
if (!(nameW = FILE_name_AtoW( name, FALSE ))) return INVALID_FILE_SIZE;
return GetCompressedFileSizeW( nameW, size_high );
}
......
......@@ -50,12 +50,17 @@ extern HMODULE kernel32_handle;
#define DOS_TABLE_SIZE 256
extern HANDLE dos_handles[DOS_TABLE_SIZE];
extern WCHAR *DIR_Windows;
extern WCHAR *DIR_System;
extern void PTHREAD_Init(void);
extern BOOL WOWTHUNK_Init(void);
extern VOID SYSLEVEL_CheckNotLevel( INT level );
extern void FILE_SetDosError(void);
extern WCHAR *FILE_name_AtoW( LPCSTR name, BOOL alloc );
extern DWORD FILE_name_WtoA( LPCWSTR src, INT srclen, LPSTR dest, INT destlen );
extern DWORD INSTR_EmulateInstruction( EXCEPTION_RECORD *rec, CONTEXT86 *context );
extern void INSTR_CallBuiltinHandler( CONTEXT86 *context, BYTE intnum );
......
......@@ -387,21 +387,11 @@ BOOL WINAPI GetBinaryTypeA( LPCSTR lpApplicationName, LPDWORD lpBinaryType )
*/
HMODULE WINAPI GetModuleHandleA(LPCSTR module)
{
NTSTATUS nts;
HMODULE ret;
UNICODE_STRING wstr;
WCHAR *moduleW;
if (!module) return NtCurrentTeb()->Peb->ImageBaseAddress;
RtlCreateUnicodeStringFromAsciiz(&wstr, module);
nts = LdrGetDllHandle(0, 0, &wstr, &ret);
RtlFreeUnicodeString( &wstr );
if (nts != STATUS_SUCCESS)
{
ret = 0;
SetLastError( RtlNtStatusToDosError( nts ) );
}
return ret;
if (!(moduleW = FILE_name_AtoW( module, FALSE ))) return 0;
return GetModuleHandleW( moduleW );
}
/***********************************************************************
......@@ -456,7 +446,7 @@ DWORD WINAPI GetModuleFileNameA(
return 0;
}
GetModuleFileNameW( hModule, filenameW, size );
WideCharToMultiByte( CP_ACP, 0, filenameW, -1, lpFileName, size, NULL, NULL );
FILE_name_WtoA( filenameW, -1, lpFileName, size );
HeapFree( GetProcessHeap(), 0, filenameW );
return strlen( lpFileName );
}
......@@ -691,18 +681,10 @@ static HMODULE load_library( const UNICODE_STRING *libname, DWORD flags )
*/
HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
{
UNICODE_STRING wstr;
HMODULE hModule;
WCHAR *libnameW;
if (!libname)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
RtlCreateUnicodeStringFromAsciiz( &wstr, libname );
hModule = load_library( &wstr, flags );
RtlFreeUnicodeString( &wstr );
return hModule;
if (!(libnameW = FILE_name_AtoW( libname, FALSE ))) return 0;
return LoadLibraryExW( libnameW, hfile, flags );
}
/***********************************************************************
......
......@@ -62,7 +62,6 @@ static HANDLE main_exe_file;
static DWORD shutdown_flags = 0;
static DWORD shutdown_priority = 0x280;
static DWORD process_dword;
static BOOL oem_file_apis;
static unsigned int server_startticks;
int main_create_flags = 0;
......@@ -117,8 +116,7 @@ inline static int is_special_env_var( const char *var )
static BOOL get_builtin_path( const WCHAR *libname, const WCHAR *ext, WCHAR *filename, UINT size )
{
WCHAR *file_part;
WCHAR sysdir[MAX_PATH];
UINT len = GetSystemDirectoryW( sysdir, MAX_PATH );
UINT len = strlenW( DIR_System );
if (contains_path( libname ))
{
......@@ -126,7 +124,7 @@ static BOOL get_builtin_path( const WCHAR *libname, const WCHAR *ext, WCHAR *fil
filename, &file_part ) > size * sizeof(WCHAR))
return FALSE; /* too long */
if (strncmpiW( filename, sysdir, len ) || filename[len] != '\\')
if (strncmpiW( filename, DIR_System, len ) || filename[len] != '\\')
return FALSE;
while (filename[len] == '\\') len++;
if (filename + len != file_part) return FALSE;
......@@ -134,7 +132,7 @@ static BOOL get_builtin_path( const WCHAR *libname, const WCHAR *ext, WCHAR *fil
else
{
if (strlenW(libname) + len + 2 >= size) return FALSE; /* too long */
memcpy( filename, sysdir, len * sizeof(WCHAR) );
memcpy( filename, DIR_System, len * sizeof(WCHAR) );
file_part = filename + len;
if (file_part > filename && file_part[-1] != '\\') *file_part++ = '\\';
strcpyW( file_part, libname );
......@@ -1602,20 +1600,19 @@ BOOL WINAPI CreateProcessA( LPCSTR app_name, LPSTR cmd_line, LPSECURITY_ATTRIBUT
DWORD flags, LPVOID env, LPCSTR cur_dir,
LPSTARTUPINFOA startup_info, LPPROCESS_INFORMATION info )
{
BOOL ret;
UNICODE_STRING app_nameW, cmd_lineW, cur_dirW, desktopW, titleW;
BOOL ret = FALSE;
WCHAR *app_nameW = NULL, *cmd_lineW = NULL, *cur_dirW = NULL;
UNICODE_STRING desktopW, titleW;
STARTUPINFOW infoW;
if (app_name) RtlCreateUnicodeStringFromAsciiz( &app_nameW, app_name );
else app_nameW.Buffer = NULL;
if (cmd_line) RtlCreateUnicodeStringFromAsciiz( &cmd_lineW, cmd_line );
else cmd_lineW.Buffer = NULL;
if (cur_dir) RtlCreateUnicodeStringFromAsciiz( &cur_dirW, cur_dir );
else cur_dirW.Buffer = NULL;
desktopW.Buffer = NULL;
titleW.Buffer = NULL;
if (app_name && !(app_nameW = FILE_name_AtoW( app_name, TRUE ))) goto done;
if (cmd_line && !(cmd_lineW = FILE_name_AtoW( cmd_line, TRUE ))) goto done;
if (cur_dir && !(cur_dirW = FILE_name_AtoW( cur_dir, TRUE ))) goto done;
if (startup_info->lpDesktop) RtlCreateUnicodeStringFromAsciiz( &desktopW, startup_info->lpDesktop );
else desktopW.Buffer = NULL;
if (startup_info->lpTitle) RtlCreateUnicodeStringFromAsciiz( &titleW, startup_info->lpTitle );
else titleW.Buffer = NULL;
memcpy( &infoW, startup_info, sizeof(infoW) );
infoW.lpDesktop = desktopW.Buffer;
......@@ -1625,12 +1622,12 @@ BOOL WINAPI CreateProcessA( LPCSTR app_name, LPSTR cmd_line, LPSECURITY_ATTRIBUT
FIXME("StartupInfo.lpReserved is used, please report (%s)\n",
debugstr_a(startup_info->lpReserved));
ret = CreateProcessW( app_nameW.Buffer, cmd_lineW.Buffer, process_attr, thread_attr,
inherit, flags, env, cur_dirW.Buffer, &infoW, info );
RtlFreeUnicodeString( &app_nameW );
RtlFreeUnicodeString( &cmd_lineW );
RtlFreeUnicodeString( &cur_dirW );
ret = CreateProcessW( app_nameW, cmd_lineW, process_attr, thread_attr,
inherit, flags, env, cur_dirW, &infoW, info );
done:
if (app_nameW) HeapFree( GetProcessHeap(), 0, app_nameW );
if (cmd_lineW) HeapFree( GetProcessHeap(), 0, cmd_lineW );
if (cur_dirW) HeapFree( GetProcessHeap(), 0, cur_dirW );
RtlFreeUnicodeString( &desktopW );
RtlFreeUnicodeString( &titleW );
return ret;
......@@ -2618,37 +2615,6 @@ DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
}
/**************************************************************************
* SetFileApisToOEM (KERNEL32.@)
*/
VOID WINAPI SetFileApisToOEM(void)
{
oem_file_apis = TRUE;
}
/**************************************************************************
* SetFileApisToANSI (KERNEL32.@)
*/
VOID WINAPI SetFileApisToANSI(void)
{
oem_file_apis = FALSE;
}
/******************************************************************************
* AreFileApisANSI [KERNEL32.@] Determines if file functions are using ANSI
*
* RETURNS
* TRUE: Set of file functions is using ANSI code page
* FALSE: Set of file functions is using OEM code page
*/
BOOL WINAPI AreFileApisANSI(void)
{
return !oem_file_apis;
}
/***********************************************************************
* GetSystemMSecCount (SYSTEM.6)
* GetTickCount (KERNEL32.@)
......
......@@ -859,27 +859,26 @@ fill_fs_info: /* now fill in the information that depends on the file system ty
* GetVolumeInformationA (KERNEL32.@)
*/
BOOL WINAPI GetVolumeInformationA( LPCSTR root, LPSTR label,
DWORD label_len, DWORD *serial,
DWORD *filename_len, DWORD *flags,
LPSTR fsname, DWORD fsname_len )
DWORD label_len, DWORD *serial,
DWORD *filename_len, DWORD *flags,
LPSTR fsname, DWORD fsname_len )
{
UNICODE_STRING rootW;
WCHAR *rootW = NULL;
LPWSTR labelW, fsnameW;
BOOL ret;
if (root) RtlCreateUnicodeStringFromAsciiz(&rootW, root);
else rootW.Buffer = NULL;
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
labelW = label ? HeapAlloc(GetProcessHeap(), 0, label_len * sizeof(WCHAR)) : NULL;
fsnameW = fsname ? HeapAlloc(GetProcessHeap(), 0, fsname_len * sizeof(WCHAR)) : NULL;
if ((ret = GetVolumeInformationW(rootW.Buffer, labelW, label_len, serial,
if ((ret = GetVolumeInformationW(rootW, labelW, label_len, serial,
filename_len, flags, fsnameW, fsname_len)))
{
if (label) WideCharToMultiByte(CP_ACP, 0, labelW, -1, label, label_len, NULL, NULL);
if (fsname) WideCharToMultiByte(CP_ACP, 0, fsnameW, -1, fsname, fsname_len, NULL, NULL);
if (label) FILE_name_WtoA( labelW, -1, label, label_len );
if (fsname) FILE_name_WtoA( fsnameW, -1, fsname, fsname_len );
}
RtlFreeUnicodeString(&rootW);
if (labelW) HeapFree( GetProcessHeap(), 0, labelW );
if (fsnameW) HeapFree( GetProcessHeap(), 0, fsnameW );
return ret;
......@@ -989,18 +988,13 @@ BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label )
*/
BOOL WINAPI SetVolumeLabelA(LPCSTR root, LPCSTR volname)
{
UNICODE_STRING rootW, volnameW;
WCHAR *rootW = NULL, *volnameW = NULL;
BOOL ret;
if (root) RtlCreateUnicodeStringFromAsciiz(&rootW, root);
else rootW.Buffer = NULL;
if (volname) RtlCreateUnicodeStringFromAsciiz(&volnameW, volname);
else volnameW.Buffer = NULL;
ret = SetVolumeLabelW( rootW.Buffer, volnameW.Buffer );
RtlFreeUnicodeString(&rootW);
RtlFreeUnicodeString(&volnameW);
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
if (volname && !(volnameW = FILE_name_AtoW( volname, TRUE ))) return FALSE;
ret = SetVolumeLabelW( rootW, volnameW );
if (volnameW) HeapFree( GetProcessHeap(), 0, volnameW );
return ret;
}
......@@ -1091,23 +1085,13 @@ BOOL WINAPI DefineDosDeviceW( DWORD flags, LPCWSTR devname, LPCWSTR targetpath )
*/
BOOL WINAPI DefineDosDeviceA(DWORD flags, LPCSTR devname, LPCSTR targetpath)
{
UNICODE_STRING d, t;
WCHAR *devW, *targetW = NULL;
BOOL ret;
if (!RtlCreateUnicodeStringFromAsciiz(&d, devname))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
if (!RtlCreateUnicodeStringFromAsciiz(&t, targetpath))
{
RtlFreeUnicodeString(&d);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
ret = DefineDosDeviceW(flags, d.Buffer, t.Buffer);
RtlFreeUnicodeString(&d);
RtlFreeUnicodeString(&t);
if (!(devW = FILE_name_AtoW( devname, FALSE ))) return FALSE;
if (targetpath && !(targetW = FILE_name_AtoW( targetpath, TRUE ))) return FALSE;
ret = DefineDosDeviceW(flags, devW, targetW);
if (targetW) HeapFree( GetProcessHeap(), 0, targetW );
return ret;
}
......@@ -1306,23 +1290,22 @@ DWORD WINAPI QueryDosDeviceW( LPCWSTR devname, LPWSTR target, DWORD bufsize )
DWORD WINAPI QueryDosDeviceA( LPCSTR devname, LPSTR target, DWORD bufsize )
{
DWORD ret = 0, retW;
UNICODE_STRING devnameW;
LPWSTR targetW = HeapAlloc( GetProcessHeap(),0, bufsize * sizeof(WCHAR) );
WCHAR *devnameW;
LPWSTR targetW;
if (!(devnameW = FILE_name_AtoW( devname, FALSE ))) return 0;
targetW = HeapAlloc( GetProcessHeap(),0, bufsize * sizeof(WCHAR) );
if (!targetW)
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return 0;
}
if (devname) RtlCreateUnicodeStringFromAsciiz(&devnameW, devname);
else devnameW.Buffer = NULL;
retW = QueryDosDeviceW(devnameW.Buffer, targetW, bufsize);
retW = QueryDosDeviceW(devnameW, targetW, bufsize);
ret = WideCharToMultiByte(CP_ACP, 0, targetW, retW, target, bufsize, NULL, NULL);
ret = FILE_name_WtoA( targetW, retW, target, bufsize );
RtlFreeUnicodeString(&devnameW);
HeapFree(GetProcessHeap(), 0, targetW);
return ret;
}
......@@ -1472,23 +1455,10 @@ UINT WINAPI GetDriveTypeW(LPCWSTR root) /* [in] String describing drive */
*/
UINT WINAPI GetDriveTypeA( LPCSTR root )
{
UNICODE_STRING rootW;
UINT ret;
WCHAR *rootW = NULL;
if (root)
{
if( !RtlCreateUnicodeStringFromAsciiz(&rootW, root))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return DRIVE_NO_ROOT_DIR;
}
}
else rootW.Buffer = NULL;
ret = GetDriveTypeW(rootW.Buffer);
RtlFreeUnicodeString(&rootW);
return ret;
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return DRIVE_NO_ROOT_DIR;
return GetDriveTypeW( rootW );
}
......@@ -1540,16 +1510,10 @@ BOOL WINAPI GetDiskFreeSpaceExW( LPCWSTR root, PULARGE_INTEGER avail,
BOOL WINAPI GetDiskFreeSpaceExA( LPCSTR root, PULARGE_INTEGER avail,
PULARGE_INTEGER total, PULARGE_INTEGER totalfree )
{
UNICODE_STRING rootW;
BOOL ret;
WCHAR *rootW = NULL;
if (root) RtlCreateUnicodeStringFromAsciiz(&rootW, root);
else rootW.Buffer = NULL;
ret = GetDiskFreeSpaceExW( rootW.Buffer, avail, total, totalfree);
RtlFreeUnicodeString(&rootW);
return ret;
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
return GetDiskFreeSpaceExW( rootW, avail, total, totalfree );
}
......@@ -1602,22 +1566,8 @@ BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors,
LPDWORD sector_bytes, LPDWORD free_clusters,
LPDWORD total_clusters )
{
UNICODE_STRING rootW;
BOOL ret = FALSE;
WCHAR *rootW = NULL;
if (root)
{
if(!RtlCreateUnicodeStringFromAsciiz(&rootW, root))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
}
else rootW.Buffer = NULL;
ret = GetDiskFreeSpaceW(rootW.Buffer, cluster_sectors, sector_bytes,
free_clusters, total_clusters );
RtlFreeUnicodeString(&rootW);
return ret;
if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
return GetDiskFreeSpaceW( rootW, cluster_sectors, sector_bytes, free_clusters, total_clusters );
}
......@@ -53,8 +53,8 @@ WINE_DECLARE_DEBUG_CHANNEL(file);
#define MAX_PATHNAME_LEN 1024
static WCHAR *DIR_Windows;
static WCHAR *DIR_System;
WCHAR *DIR_Windows = NULL;
WCHAR *DIR_System = NULL;
/***********************************************************************
* DIR_GetPath
......@@ -233,93 +233,3 @@ int DIR_Init(void)
return 1;
}
/***********************************************************************
* GetWindowsDirectoryW (KERNEL32.@)
*
* See comment for GetWindowsDirectoryA.
*/
UINT WINAPI GetWindowsDirectoryW( LPWSTR path, UINT count )
{
UINT len = strlenW( DIR_Windows ) + 1;
if (path && count >= len)
{
strcpyW( path, DIR_Windows );
len--;
}
return len;
}
/***********************************************************************
* GetWindowsDirectoryA (KERNEL32.@)
*
* Return value:
* If buffer is large enough to hold full path and terminating '\0' character
* function copies path to buffer and returns length of the path without '\0'.
* Otherwise function returns required size including '\0' character and
* does not touch the buffer.
*/
UINT WINAPI GetWindowsDirectoryA( LPSTR path, UINT count )
{
UINT len = WideCharToMultiByte( CP_ACP, 0, DIR_Windows, -1, NULL, 0, NULL, NULL );
if (path && count >= len)
{
WideCharToMultiByte( CP_ACP, 0, DIR_Windows, -1, path, count, NULL, NULL );
len--;
}
return len;
}
/***********************************************************************
* GetSystemWindowsDirectoryA (KERNEL32.@) W2K, TS4.0SP4
*/
UINT WINAPI GetSystemWindowsDirectoryA( LPSTR path, UINT count )
{
return GetWindowsDirectoryA( path, count );
}
/***********************************************************************
* GetSystemWindowsDirectoryW (KERNEL32.@) W2K, TS4.0SP4
*/
UINT WINAPI GetSystemWindowsDirectoryW( LPWSTR path, UINT count )
{
return GetWindowsDirectoryW( path, count );
}
/***********************************************************************
* GetSystemDirectoryW (KERNEL32.@)
*
* See comment for GetWindowsDirectoryA.
*/
UINT WINAPI GetSystemDirectoryW( LPWSTR path, UINT count )
{
UINT len = strlenW( DIR_System ) + 1;
if (path && count >= len)
{
strcpyW( path, DIR_System );
len--;
}
return len;
}
/***********************************************************************
* GetSystemDirectoryA (KERNEL32.@)
*
* See comment for GetWindowsDirectoryA.
*/
UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count )
{
UINT len = WideCharToMultiByte( CP_ACP, 0, DIR_System, -1, NULL, 0, NULL, NULL );
if (path && count >= len)
{
WideCharToMultiByte( CP_ACP, 0, DIR_System, -1, path, count, NULL, NULL );
len--;
}
return len;
}
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