From 1c5d2b7204f2ee6efc2ad7ccf2564d220b9595cc Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 14 Mar 2000 23:09:23 +0000 Subject: [PATCH] Fixed ANSI/OEM <--> Unicode conversions svn path=/trunk/; revision=1056 --- reactos/lib/kernel32/file/copy.c | 252 ++++++++++++++---------- reactos/lib/kernel32/file/create.c | 252 +++++++++++------------- reactos/lib/kernel32/file/curdir.c | 276 ++++++++++++++++++--------- reactos/lib/kernel32/file/delete.c | 221 ++++++++++----------- reactos/lib/kernel32/file/deviceio.c | 159 +++++++++------ reactos/lib/kernel32/file/lfile.c | 47 ++--- reactos/lib/kernel32/file/move.c | 186 ++++++++++-------- 7 files changed, 775 insertions(+), 618 deletions(-) diff --git a/reactos/lib/kernel32/file/copy.c b/reactos/lib/kernel32/file/copy.c index 96293ea9821..96999489db5 100644 --- a/reactos/lib/kernel32/file/copy.c +++ b/reactos/lib/kernel32/file/copy.c @@ -1,9 +1,10 @@ -/* +/* $Id: copy.c,v 1.6 2000/03/14 23:09:23 ekohl Exp $ + * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/kernel32/file/copy.c * PURPOSE: Copying files - * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * PROGRAMMER: Ariadne (ariadne@xs4all.nl) * UPDATE HISTORY: * 01/11/98 Created * 07/02/99 Moved to seperate file @@ -13,22 +14,26 @@ #include #include -#include -#include #define NDEBUG #include + #define LPPROGRESS_ROUTINE void* + /* FUNCTIONS ****************************************************************/ -WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, - LPCWSTR lpNewFileName, - LPPROGRESS_ROUTINE lpProgressRoutine, - LPVOID lpData, - WINBOOL * pbCancel, - DWORD dwCopyFlags) +WINBOOL +STDCALL +CopyFileExW ( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName, + LPPROGRESS_ROUTINE lpProgressRoutine, + LPVOID lpData, + WINBOOL *pbCancel, + DWORD dwCopyFlags + ) { NTSTATUS errCode = 0; HANDLE FileHandleSource, FileHandleDest; @@ -40,24 +45,24 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, ULONG RegionSize = 0x1000000; BOOL bCancel = FALSE; - FileHandleSource = CreateFileW(lpExistingFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, + FileHandleSource = CreateFileW(lpExistingFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL); if (FileHandleSource == NULL) { return(FALSE); } - + errCode = NtQueryInformationFile(FileHandleSource, &IoStatusBlock, - &FileStandard, + &FileStandard, sizeof(FILE_STANDARD_INFORMATION), FileStandardInformation); - if (!NT_SUCCESS(errCode)) + if (!NT_SUCCESS(errCode)) { NtClose(FileHandleSource); SetLastError(RtlNtStatusToDosError(errCode)); @@ -65,21 +70,21 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, } errCode = NtQueryInformationFile(FileHandleSource, - &IoStatusBlock,&FileBasic, + &IoStatusBlock,&FileBasic, sizeof(FILE_BASIC_INFORMATION), FileBasicInformation); - if (!NT_SUCCESS(errCode)) + if (!NT_SUCCESS(errCode)) { NtClose(FileHandleSource); SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; } - - FileHandleDest = CreateFileW(lpNewFileName, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - dwCopyFlags ? CREATE_NEW : CREATE_ALWAYS , + + FileHandleDest = CreateFileW(lpNewFileName, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + dwCopyFlags ? CREATE_NEW : CREATE_ALWAYS, FileBasic.FileAttributes|FILE_FLAG_NO_BUFFERING, NULL); if (FileHandleDest == NULL) @@ -88,23 +93,10 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, } FilePosition.CurrentByteOffset.QuadPart = 0; - + errCode = NtSetInformationFile(FileHandleSource, &IoStatusBlock, - &FilePosition, - sizeof(FILE_POSITION_INFORMATION), - FilePositionInformation); - if (!NT_SUCCESS(errCode)) - { - NtClose(FileHandleSource); - NtClose(FileHandleDest); - SetLastError(RtlNtStatusToDosError(errCode)); - return FALSE; - } - - errCode = NtSetInformationFile(FileHandleDest, - &IoStatusBlock, - &FilePosition, + &FilePosition, sizeof(FILE_POSITION_INFORMATION), FilePositionInformation); if (!NT_SUCCESS(errCode)) @@ -113,23 +105,36 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, NtClose(FileHandleDest); SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; - } + } - errCode = NtAllocateVirtualMemory(NtCurrentProcess(), - (PVOID *)&lpBuffer, - 2, - &RegionSize, - MEM_COMMIT, - PAGE_READWRITE); - - if (!NT_SUCCESS(errCode)) + errCode = NtSetInformationFile(FileHandleDest, + &IoStatusBlock, + &FilePosition, + sizeof(FILE_POSITION_INFORMATION), + FilePositionInformation); + if (!NT_SUCCESS(errCode)) { NtClose(FileHandleSource); NtClose(FileHandleDest); SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; - } - + } + + errCode = NtAllocateVirtualMemory(NtCurrentProcess(), + (PVOID *)&lpBuffer, + 2, + &RegionSize, + MEM_COMMIT, + PAGE_READWRITE); + + if (!NT_SUCCESS(errCode)) + { + NtClose(FileHandleSource); + NtClose(FileHandleDest); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + do { errCode = NtReadFile(FileHandleSource, NULL, @@ -142,7 +147,7 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, NULL); if (pbCancel != NULL) bCancel = *pbCancel; - + if (!NT_SUCCESS(errCode) || bCancel) { NtFreeVirtualMemory(NtCurrentProcess(), @@ -152,7 +157,7 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, if ( errCode == STATUS_END_OF_FILE ) break; else - return FALSE; + return FALSE; } errCode = NtWriteFile(FileHandleDest, @@ -164,11 +169,11 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, RegionSize, NULL, NULL); - - if (!NT_SUCCESS(errCode)) + + if (!NT_SUCCESS(errCode)) { NtFreeVirtualMemory(NtCurrentProcess(), - (PVOID *)&lpBuffer, + (PVOID *)&lpBuffer, &RegionSize, MEM_RELEASE); NtClose(FileHandleSource); @@ -180,56 +185,99 @@ WINBOOL STDCALL CopyFileExW(LPCWSTR lpExistingFileName, return TRUE; } -WINBOOL STDCALL CopyFileExA(LPCSTR lpExistingFileName, - LPCSTR lpNewFileName, - LPPROGRESS_ROUTINE lpProgressRoutine, - LPVOID lpData, - WINBOOL* pbCancel, - DWORD dwCopyFlags) + +WINBOOL +STDCALL +CopyFileExA ( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName, + LPPROGRESS_ROUTINE lpProgressRoutine, + LPVOID lpData, + WINBOOL *pbCancel, + DWORD dwCopyFlags + ) { - WCHAR ExistingFileNameW[MAX_PATH]; - WCHAR NewFileNameW[MAX_PATH]; - - if (!KERNEL32_AnsiToUnicode(ExistingFileNameW, - lpExistingFileName, - MAX_PATH)) - { - return(FALSE); - } - if (!KERNEL32_AnsiToUnicode(NewFileNameW, - lpNewFileName, - MAX_PATH)) - { - return(FALSE); - } - return(CopyFileExW(ExistingFileNameW, - NewFileNameW, - lpProgressRoutine, - lpData, - pbCancel, - dwCopyFlags)); + UNICODE_STRING ExistingFileNameU; + UNICODE_STRING NewFileNameU; + ANSI_STRING ExistingFileName; + ANSI_STRING NewFileName; + WINBOOL Result; + + RtlInitAnsiString (&ExistingFileName, + (LPSTR)lpExistingFileName); + + RtlInitAnsiString (&NewFileName, + (LPSTR)lpNewFileName); + + /* convert ansi (or oem) string to unicode */ + if (bIsFileApiAnsi) + { + RtlAnsiStringToUnicodeString (&ExistingFileNameU, + &ExistingFileName, + TRUE); + RtlAnsiStringToUnicodeString (&NewFileNameU, + &NewFileName, + TRUE); + } + else + { + RtlOemStringToUnicodeString (&ExistingFileNameU, + &ExistingFileName, + TRUE); + RtlOemStringToUnicodeString (&NewFileNameU, + &NewFileName, + TRUE); + } + + Result = CopyFileExW (ExistingFileNameU.Buffer, + NewFileNameU.Buffer, + lpProgressRoutine, + lpData, + pbCancel, + dwCopyFlags); + + RtlFreeHeap (RtlGetProcessHeap (), + 0, + ExistingFileNameU.Buffer); + RtlFreeHeap (RtlGetProcessHeap (), + 0, + NewFileNameU.Buffer); + + return Result; } -WINBOOL STDCALL CopyFileA(LPCSTR lpExistingFileName, - LPCSTR lpNewFileName, - WINBOOL bFailIfExists) +WINBOOL +STDCALL +CopyFileA ( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName, + WINBOOL bFailIfExists + ) { - return CopyFileExA(lpExistingFileName, - lpNewFileName, - NULL, - NULL, - FALSE, - bFailIfExists); + return CopyFileExA (lpExistingFileName, + lpNewFileName, + NULL, + NULL, + NULL, + bFailIfExists); } -WINBOOL STDCALL CopyFileW(LPCWSTR lpExistingFileName, - LPCWSTR lpNewFileName, - WINBOOL bFailIfExists) + + +WINBOOL +STDCALL +CopyFileW ( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName, + WINBOOL bFailIfExists + ) { - return CopyFileExW(lpExistingFileName, - lpNewFileName, - NULL, - NULL, - NULL, - bFailIfExists); + return CopyFileExW (lpExistingFileName, + lpNewFileName, + NULL, + NULL, + NULL, + bFailIfExists); } + +/* EOF */ diff --git a/reactos/lib/kernel32/file/create.c b/reactos/lib/kernel32/file/create.c index d1b6dfca0e5..e3728b79c11 100644 --- a/reactos/lib/kernel32/file/create.c +++ b/reactos/lib/kernel32/file/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.18 2000/01/21 23:27:47 phreak Exp $ +/* $Id: create.c,v 1.19 2000/03/14 23:09:23 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -14,9 +14,8 @@ /* INCLUDES *****************************************************************/ #include +#include #include -#include -#include #define NDEBUG #include @@ -24,163 +23,140 @@ /* FUNCTIONS ****************************************************************/ -HANDLE STDCALL CreateFileA(LPCSTR lpFileName, - DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile) +HANDLE +STDCALL +CreateFileA ( + LPCSTR lpFileName, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile + ) { - WCHAR FileNameW[MAX_PATH]; - ULONG i = 0; + UNICODE_STRING FileNameU; + ANSI_STRING FileName; + HANDLE FileHandle; - DPRINT("CreateFileA(lpFileName %s)\n",lpFileName); + DPRINT("CreateFileA(lpFileName %s)\n",lpFileName); - while ((*lpFileName)!=0 && i < MAX_PATH) - { - FileNameW[i] = *lpFileName; - lpFileName++; - i++; - } - FileNameW[i] = 0; + RtlInitAnsiString (&FileName, + (LPSTR)lpFileName); - return CreateFileW(FileNameW,dwDesiredAccess, - dwShareMode, - lpSecurityAttributes, - dwCreationDisposition, - dwFlagsAndAttributes, - hTemplateFile); + /* convert ansi (or oem) string to unicode */ + if (bIsFileApiAnsi) + RtlAnsiStringToUnicodeString (&FileNameU, + &FileName, + TRUE); + else + RtlOemStringToUnicodeString (&FileNameU, + &FileName, + TRUE); + + FileHandle = CreateFileW (FileNameU.Buffer, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); + + RtlFreeHeap (RtlGetProcessHeap (), + 0, + FileNameU.Buffer); + + return FileHandle; } -HANDLE STDCALL CreateFileW(LPCWSTR lpFileName, - DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile) +HANDLE +STDCALL +CreateFileW ( + LPCWSTR lpFileName, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile + ) { - HANDLE FileHandle; - NTSTATUS Status; - OBJECT_ATTRIBUTES ObjectAttributes; - IO_STATUS_BLOCK IoStatusBlock; - UNICODE_STRING FileNameString; - ULONG Flags = 0; - WCHAR PathNameW[MAX_PATH]; - WCHAR FileNameW[MAX_PATH]; - UINT Len = 0; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING NtPathU; + HANDLE FileHandle; + NTSTATUS Status; + ULONG Flags = 0; - switch (dwCreationDisposition) - { - case CREATE_NEW: - dwCreationDisposition = FILE_CREATE; - break; + switch (dwCreationDisposition) + { + case CREATE_NEW: + dwCreationDisposition = FILE_CREATE; + break; - case CREATE_ALWAYS: - dwCreationDisposition = FILE_OVERWRITE_IF; - break; + case CREATE_ALWAYS: + dwCreationDisposition = FILE_OVERWRITE_IF; + break; - case OPEN_EXISTING: - dwCreationDisposition = FILE_OPEN; - break; + case OPEN_EXISTING: + dwCreationDisposition = FILE_OPEN; + break; - case OPEN_ALWAYS: - dwCreationDisposition = OPEN_ALWAYS; - break; + case OPEN_ALWAYS: + dwCreationDisposition = OPEN_ALWAYS; + break; - case TRUNCATE_EXISTING: - dwCreationDisposition = FILE_OVERWRITE; - } - - DPRINT("CreateFileW(lpFileName %S)\n",lpFileName); - - if (dwDesiredAccess & GENERIC_READ) - dwDesiredAccess |= FILE_GENERIC_READ; - - if (dwDesiredAccess & GENERIC_WRITE) - dwDesiredAccess |= FILE_GENERIC_WRITE; - - if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED)) - { - Flags |= FILE_SYNCHRONOUS_IO_ALERT; - } - - if (lpFileName[1] == (WCHAR)':') - { - wcscpy(PathNameW, lpFileName); - } - else if (wcslen(lpFileName) > 4 && - lpFileName[0] == (WCHAR)'\\' && - lpFileName[1] == (WCHAR)'\\' && - lpFileName[2] == (WCHAR)'.' && - lpFileName[3] == (WCHAR)'\\') - { - wcscpy(PathNameW, lpFileName+4); - } - else if (lpFileName[0] == (WCHAR)'\\') - { - GetCurrentDirectoryW(MAX_PATH,PathNameW); - PathNameW[3] = 0; - wcscat(PathNameW, lpFileName); - } - else - { - Len = GetCurrentDirectoryW(MAX_PATH,PathNameW); - if ( Len == 0 ) - return NULL; - if ( PathNameW[Len-1] != L'\\' ) { - PathNameW[Len] = L'\\'; - PathNameW[Len+1] = 0; + case TRUNCATE_EXISTING: + dwCreationDisposition = FILE_OVERWRITE; } - wcscat(PathNameW,lpFileName); - } - FileNameW[0] = '\\'; - FileNameW[1] = '?'; - FileNameW[2] = '?'; - FileNameW[3] = '\\'; - FileNameW[4] = 0; - wcscat(FileNameW,PathNameW); + DPRINT("CreateFileW(lpFileName %S)\n",lpFileName); - FileNameString.Length = wcslen( FileNameW)*sizeof(WCHAR); + if (dwDesiredAccess & GENERIC_READ) + dwDesiredAccess |= FILE_GENERIC_READ; - if ( FileNameString.Length == 0 ) - return NULL; + if (dwDesiredAccess & GENERIC_WRITE) + dwDesiredAccess |= FILE_GENERIC_WRITE; - if ( FileNameString.Length > MAX_PATH*sizeof(WCHAR) ) - return NULL; + if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED)) + { + Flags |= FILE_SYNCHRONOUS_IO_ALERT; + } - FileNameString.Buffer = (WCHAR *)FileNameW; - FileNameString.MaximumLength = FileNameString.Length + sizeof(WCHAR); + if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName, + &NtPathU, + NULL, + NULL)) + return FALSE; - ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); - ObjectAttributes.RootDirectory = NULL; - ObjectAttributes.ObjectName = &FileNameString; - ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; - ObjectAttributes.SecurityDescriptor = NULL; - ObjectAttributes.SecurityQualityOfService = NULL; + DPRINT("NtPathU \'%S\'\n", NtPathU.Buffer); - DPRINT("File Name %S\n",FileNameW); + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &NtPathU; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; - Status = ZwCreateFile(&FileHandle, - dwDesiredAccess, - &ObjectAttributes, - &IoStatusBlock, - NULL, - dwFlagsAndAttributes, - dwShareMode, - dwCreationDisposition, - Flags, - NULL, - 0); - if (!NT_SUCCESS(Status)) - { - SetLastError(RtlNtStatusToDosError(Status)); - return INVALID_HANDLE_VALUE; - } - return(FileHandle); + Status = NtCreateFile (&FileHandle, + dwDesiredAccess, + &ObjectAttributes, + &IoStatusBlock, + NULL, + dwFlagsAndAttributes, + dwShareMode, + dwCreationDisposition, + Flags, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { + SetLastError (RtlNtStatusToDosError (Status)); + return INVALID_HANDLE_VALUE; + } + + return FileHandle; } /* EOF */ diff --git a/reactos/lib/kernel32/file/curdir.c b/reactos/lib/kernel32/file/curdir.c index a408c74e81e..bce9aa64e85 100644 --- a/reactos/lib/kernel32/file/curdir.c +++ b/reactos/lib/kernel32/file/curdir.c @@ -1,4 +1,4 @@ -/* $Id: curdir.c,v 1.20 2000/02/18 00:49:39 ekohl Exp $ +/* $Id: curdir.c,v 1.21 2000/03/14 23:09:23 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -21,8 +21,9 @@ /* GLOBAL VARIABLES **********************************************************/ -static WCHAR SystemDirectoryW[MAX_PATH]; -static WCHAR WindowsDirectoryW[MAX_PATH]; +/* FIXME initialize them on startup !! */ +UNICODE_STRING SystemDirectory; +UNICODE_STRING WindowsDirectory; /* FUNCTIONS *****************************************************************/ @@ -150,107 +151,206 @@ SetCurrentDirectoryW ( } -DWORD STDCALL GetTempPathA (DWORD nBufferLength, LPSTR lpBuffer) +DWORD +STDCALL +GetTempPathA ( + DWORD nBufferLength, + LPSTR lpBuffer + ) { - WCHAR BufferW[MAX_PATH]; - DWORD retCode; - UINT i; - retCode = GetTempPathW(nBufferLength,BufferW); - i = 0; - while ((BufferW[i])!=0 && i < MAX_PATH) + UNICODE_STRING UnicodeString; + ANSI_STRING AnsiString; + + AnsiString.Length = 0; + AnsiString.MaximumLength = nBufferLength; + AnsiString.Buffer = lpBuffer; + + /* initialize allocate unicode string */ + UnicodeString.Length = 0; + UnicodeString.MaximumLength = nBufferLength * sizeof(WCHAR); + UnicodeString.Buffer = RtlAllocateHeap (RtlGetProcessHeap(), + 0, + UnicodeString.MaximumLength); + + UnicodeString.Length = GetTempPathW (nBufferLength, + UnicodeString.Buffer) * sizeof(WCHAR); + + /* convert unicode string to ansi (or oem) */ + if (bIsFileApiAnsi) + RtlUnicodeStringToAnsiString (&AnsiString, + &UnicodeString, + FALSE); + else + RtlUnicodeStringToOemString (&AnsiString, + &UnicodeString, + FALSE); + + /* free unicode string buffer */ + RtlFreeHeap (RtlGetProcessHeap (), + 0, + UnicodeString.Buffer); + + return AnsiString.Length; +} + + +DWORD +STDCALL +GetTempPathW ( + DWORD nBufferLength, + LPWSTR lpBuffer + ) +{ + UNICODE_STRING Name; + UNICODE_STRING Value; + NTSTATUS Status; + + Value.Length = 0; + Value.MaximumLength = nBufferLength * sizeof(WCHAR); + Value.Buffer = lpBuffer; + + RtlInitUnicodeString (&Name, + L"TMP"); + + Status = RtlQueryEnvironmentVariable_U (NULL, + &Name, + &Value); + if (!NT_SUCCESS(Status)) { - lpBuffer[i] = (unsigned char)BufferW[i]; - i++; + RtlInitUnicodeString (&Name, + L"TEMP"); + + Status = RtlQueryEnvironmentVariable_U (NULL, + &Name, + &Value); + if (!NT_SUCCESS(Status)) + { + Value.Length = RtlGetCurrentDirectory_U (Value.MaximumLength, + Value.Buffer); + } } - lpBuffer[i] = 0; - return retCode; + + return Value.Length / sizeof(WCHAR); } -DWORD STDCALL GetTempPathW(DWORD nBufferLength, LPWSTR lpBuffer) -{ - WCHAR EnvironmentBufferW[MAX_PATH]; - UINT i; - - EnvironmentBufferW[0] = 0; - i = GetEnvironmentVariableW(L"TMP",EnvironmentBufferW,MAX_PATH); - if ( i==0 ) - i = GetEnvironmentVariableW(L"TEMP",EnvironmentBufferW,MAX_PATH); - if ( i==0 ) - i = GetCurrentDirectoryW(MAX_PATH,EnvironmentBufferW); - - return i; -} - -UINT STDCALL GetSystemDirectoryA(LPSTR lpBuffer, UINT uSize) -{ - UINT uPathSize,i; - - if ( lpBuffer == NULL ) - return 0; - uPathSize = lstrlenW(SystemDirectoryW); - if ( uSize > uPathSize ) { - i = 0; - while ((SystemDirectoryW[i])!=0 && i < uSize) - { - lpBuffer[i] = (unsigned char)SystemDirectoryW[i]; - i++; - } - lpBuffer[i] = 0; - } - - return uPathSize; -} - -UINT STDCALL GetWindowsDirectoryA(LPSTR lpBuffer, UINT uSize) -{ - UINT uPathSize,i; - if ( lpBuffer == NULL ) - return 0; - uPathSize = lstrlenW(WindowsDirectoryW); - if ( uSize > uPathSize ) { - i = 0; - while ((WindowsDirectoryW[i])!=0 && i < uSize) - { - lpBuffer[i] = (unsigned char)WindowsDirectoryW[i]; - i++; - } - lpBuffer[i] = 0; - } - return uPathSize; -} UINT STDCALL -GetSystemDirectoryW( - LPWSTR lpBuffer, - UINT uSize - ) +GetSystemDirectoryA ( + LPSTR lpBuffer, + UINT uSize + ) { - UINT uPathSize; - if ( lpBuffer == NULL ) - return 0; - uPathSize = lstrlenW(SystemDirectoryW); - if ( uSize > uPathSize ) - lstrcpynW(lpBuffer,SystemDirectoryW,uPathSize); + ANSI_STRING String; + ULONG Length; - return uPathSize; + if (lpBuffer == NULL) + return 0; + + Length = RtlUnicodeStringToAnsiSize (&SystemDirectory); + if (uSize > Length) + { + String.Length = 0; + String.MaximumLength = uSize; + String.Buffer = lpBuffer; + + /* convert unicode string to ansi (or oem) */ + if (bIsFileApiAnsi) + RtlUnicodeStringToAnsiString (&String, + &SystemDirectory, + FALSE); + else + RtlUnicodeStringToOemString (&String, + &SystemDirectory, + FALSE); + } + + return Length; } + UINT STDCALL -GetWindowsDirectoryW( - LPWSTR lpBuffer, - UINT uSize - ) +GetSystemDirectoryW ( + LPWSTR lpBuffer, + UINT uSize + ) { - UINT uPathSize; - if ( lpBuffer == NULL ) - return 0; - uPathSize = lstrlenW(WindowsDirectoryW); - if ( uSize > uPathSize ); - lstrcpynW(lpBuffer,WindowsDirectoryW,uPathSize); + ULONG Length; - return uPathSize; + if (lpBuffer == NULL) + return 0; + + Length = SystemDirectory.Length / sizeof (WCHAR); + if (uSize > Length) + { + memmove (lpBuffer, + SystemDirectory.Buffer, + Length); + lpBuffer[Length] = 0; + } + + return Length; +} + + +UINT +STDCALL +GetWindowsDirectoryA ( + LPSTR lpBuffer, + UINT uSize + ) +{ + ANSI_STRING String; + ULONG Length; + + if (lpBuffer == NULL) + return 0; + + Length = RtlUnicodeStringToAnsiSize (&SystemDirectory); + if (uSize > Length) + { + String.Length = 0; + String.MaximumLength = uSize; + String.Buffer = lpBuffer; + + /* convert unicode string to ansi (or oem) */ + if (bIsFileApiAnsi) + RtlUnicodeStringToAnsiString (&String, + &WindowsDirectory, + FALSE); + else + RtlUnicodeStringToOemString (&String, + &WindowsDirectory, + FALSE); + } + + return Length; +} + + +UINT +STDCALL +GetWindowsDirectoryW ( + LPWSTR lpBuffer, + UINT uSize + ) +{ + ULONG Length; + + if (lpBuffer == NULL) + return 0; + + Length = SystemDirectory.Length / sizeof (WCHAR); + if (uSize > Length) + { + memmove (lpBuffer, + SystemDirectory.Buffer, + Length); + lpBuffer[Length] = 0; + } + + return Length; } /* EOF */ diff --git a/reactos/lib/kernel32/file/delete.c b/reactos/lib/kernel32/file/delete.c index 40c6a6b363e..489cc2cd2e4 100644 --- a/reactos/lib/kernel32/file/delete.c +++ b/reactos/lib/kernel32/file/delete.c @@ -1,10 +1,10 @@ -/* $Id: delete.c,v 1.5 2000/01/11 17:30:16 ekohl Exp $ +/* $Id: delete.c,v 1.6 2000/03/14 23:09:23 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/kernel32/file/delete.c * PURPOSE: Deleting files - * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * PROGRAMMER: Ariadne (ariadne@xs4all.nl) * UPDATE HISTORY: * Created 01/11/98 */ @@ -12,9 +12,8 @@ /* INCLUDES ****************************************************************/ #include +#include #include -#include -#include #define NDEBUG #include @@ -22,138 +21,112 @@ /* FUNCTIONS ****************************************************************/ -WINBOOL STDCALL DeleteFileA(LPCSTR lpFileName) +WINBOOL +STDCALL +DeleteFileA ( + LPCSTR lpFileName + ) { - ULONG i; - WCHAR FileNameW[MAX_PATH]; + UNICODE_STRING FileNameU; + ANSI_STRING FileName; + WINBOOL Result; - i = 0; - while ((*lpFileName)!=0 && i < MAX_PATH) - { - FileNameW[i] = *lpFileName; - lpFileName++; - i++; - } - FileNameW[i] = 0; - return DeleteFileW(FileNameW); + RtlInitAnsiString (&FileName, + (LPSTR)lpFileName); + + /* convert ansi (or oem) string to unicode */ + if (bIsFileApiAnsi) + RtlAnsiStringToUnicodeString (&FileNameU, + &FileName, + TRUE); + else + RtlOemStringToUnicodeString (&FileNameU, + &FileName, + TRUE); + + Result = DeleteFileW (FileNameU.Buffer); + + RtlFreeHeap (RtlGetProcessHeap (), + 0, + FileNameU.Buffer); + + return Result; } -WINBOOL STDCALL DeleteFileW(LPCWSTR lpFileName) + +WINBOOL +STDCALL +DeleteFileW ( + LPCWSTR lpFileName + ) { - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING FileNameString; - NTSTATUS errCode; - WCHAR PathNameW[MAX_PATH]; - WCHAR FileNameW[MAX_PATH]; - HANDLE FileHandle; - FILE_DISPOSITION_INFORMATION FileDispInfo; - IO_STATUS_BLOCK IoStatusBlock; - UINT Len; + FILE_DISPOSITION_INFORMATION FileDispInfo; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING NtPathU; + HANDLE FileHandle; + NTSTATUS Status; - DPRINT("DeleteFileW (lpFileName %S)\n",lpFileName); + DPRINT("DeleteFileW (lpFileName %S)\n",lpFileName); - if (lpFileName[1] == (WCHAR)':') - { - wcscpy(PathNameW, lpFileName); - } - else if (wcslen(lpFileName) > 4 && - lpFileName[0] == (WCHAR)'\\' && - lpFileName[1] == (WCHAR)'\\' && - lpFileName[2] == (WCHAR)'.' && - lpFileName[3] == (WCHAR)'\\') - { - wcscpy(PathNameW, lpFileName); - } - else if (lpFileName[0] == (WCHAR)'\\') - { - GetCurrentDirectoryW(MAX_PATH,PathNameW); - PathNameW[3] = 0; - wcscat(PathNameW, lpFileName); - } - else - { - Len = GetCurrentDirectoryW(MAX_PATH,PathNameW); - if ( Len == 0 ) - return FALSE; - if ( PathNameW[Len-1] != L'\\' ) { - PathNameW[Len] = L'\\'; - PathNameW[Len+1] = 0; + if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName, + &NtPathU, + NULL, + NULL)) + return FALSE; + + DPRINT("NtPathU \'%wZ\'\n", &NtPathU); + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &NtPathU; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + Status = NtCreateFile (&FileHandle, + FILE_WRITE_ATTRIBUTES, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + 0, + FILE_OPEN, + FILE_DIRECTORY_FILE, + NULL, + 0); + + if (!NT_SUCCESS(Status)) + { + CHECKPOINT; + SetLastError (RtlNtStatusToDosError (Status)); + return FALSE; } - wcscat(PathNameW,lpFileName); - } - FileNameW[0] = '\\'; - FileNameW[1] = '?'; - FileNameW[2] = '?'; - FileNameW[3] = '\\'; - FileNameW[4] = 0; - wcscat(FileNameW,PathNameW); + FileDispInfo.DeleteFile = TRUE; - FileNameString.Length = wcslen( FileNameW)*sizeof(WCHAR); + Status = NtSetInformationFile (FileHandle, + &IoStatusBlock, + &FileDispInfo, + sizeof(FILE_DISPOSITION_INFORMATION), + FileDispositionInformation); + if (!NT_SUCCESS(Status)) + { + CHECKPOINT; + NtClose (FileHandle); + SetLastError (RtlNtStatusToDosError (Status)); + return FALSE; + } - if ( FileNameString.Length == 0 ) - return FALSE; + Status = NtClose (FileHandle); + if (!NT_SUCCESS (Status)) + { + CHECKPOINT; + SetLastError (RtlNtStatusToDosError (Status)); + return FALSE; + } - if ( FileNameString.Length > MAX_PATH*sizeof(WCHAR) ) - return FALSE; - - FileNameString.Buffer = (WCHAR *)FileNameW; - FileNameString.MaximumLength = FileNameString.Length + sizeof(WCHAR); - - ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); - ObjectAttributes.RootDirectory = NULL; - ObjectAttributes.ObjectName = &FileNameString; - ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; - ObjectAttributes.SecurityDescriptor = NULL; - ObjectAttributes.SecurityQualityOfService = NULL; - - DPRINT("FileName %S\n",FileNameW); - - errCode = ZwCreateFile(&FileHandle, - FILE_WRITE_ATTRIBUTES, - &ObjectAttributes, - &IoStatusBlock, - NULL, - FILE_ATTRIBUTE_NORMAL, - 0, - FILE_OPEN, - FILE_DIRECTORY_FILE, - NULL, - 0); - - if (!NT_SUCCESS(errCode)) - { - CHECKPOINT; - SetLastError(RtlNtStatusToDosError(errCode)); - return FALSE; - } - - FileDispInfo.DeleteFile = TRUE; - - errCode = NtSetInformationFile(FileHandle, - &IoStatusBlock, - &FileDispInfo, - sizeof(FILE_DISPOSITION_INFORMATION), - FileDispositionInformation); - - if (!NT_SUCCESS(errCode)) - { - CHECKPOINT; - NtClose(FileHandle); - SetLastError(RtlNtStatusToDosError(errCode)); - return FALSE; - } - - errCode = NtClose(FileHandle); - - if (!NT_SUCCESS(errCode)) - { - CHECKPOINT; - SetLastError(RtlNtStatusToDosError(errCode)); - return FALSE; - } - - return TRUE; + return TRUE; } /* EOF */ diff --git a/reactos/lib/kernel32/file/deviceio.c b/reactos/lib/kernel32/file/deviceio.c index b40f3eeda35..48619279393 100644 --- a/reactos/lib/kernel32/file/deviceio.c +++ b/reactos/lib/kernel32/file/deviceio.c @@ -1,4 +1,5 @@ -/* +/* $Id: deviceio.c,v 1.6 2000/03/14 23:09:23 ekohl Exp $ + * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/kernel32/file/deviceio.c @@ -35,94 +36,134 @@ DeviceIoControl( WINBOOL bFsIoControlCode = FALSE; - if ( lpBytesReturned == NULL ) { - SetLastError(RtlNtStatusToDosError(STATUS_INVALID_PARAMETER)); - return FALSE;; + if (lpBytesReturned == NULL) + { + SetLastError (RtlNtStatusToDosError (STATUS_INVALID_PARAMETER)); + return FALSE; } - if( ( ( dwIoControlCode >> 16 ) & FILE_DEVICE_FILE_SYSTEM ) == FILE_DEVICE_FILE_SYSTEM ) - bFsIoControlCode = TRUE; + if (((dwIoControlCode >> 16) & FILE_DEVICE_FILE_SYSTEM) == FILE_DEVICE_FILE_SYSTEM) + bFsIoControlCode = TRUE; else bFsIoControlCode = FALSE; - if(lpOverlapped != NULL) { + + if(lpOverlapped != NULL) + { hEvent = lpOverlapped->hEvent; lpOverlapped->Internal = STATUS_PENDING; IoStatusBlock = (PIO_STATUS_BLOCK)lpOverlapped; } - else { + else + { IoStatusBlock = &IIosb; } - if(bFsIoControlCode == TRUE) { - errCode = NtFsControlFile(hDevice,hEvent,NULL,NULL,IoStatusBlock,dwIoControlCode,lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize ); - } else { - errCode = NtDeviceIoControlFile(hDevice,hEvent,NULL,NULL,IoStatusBlock,dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize); - } - - if(errCode == STATUS_PENDING ) { - - if(NtWaitForSingleObject(hDevice,FALSE,NULL) < 0) { + if (bFsIoControlCode == TRUE) + { + errCode = NtFsControlFile (hDevice, + hEvent, + NULL, + NULL, + IoStatusBlock, + dwIoControlCode, + lpInBuffer, + nInBufferSize, + lpOutBuffer, + nOutBufferSize); + } + else + { + errCode = NtDeviceIoControlFile (hDevice, + hEvent, + NULL, + NULL, + IoStatusBlock, + dwIoControlCode, + lpInBuffer, + nInBufferSize, + lpOutBuffer, + nOutBufferSize); + } + + if (errCode == STATUS_PENDING) + { + if (NtWaitForSingleObject(hDevice,FALSE,NULL) < 0) + { *lpBytesReturned = IoStatusBlock->Information; - SetLastError(RtlNtStatusToDosError(errCode)); - return FALSE;; - } - - } else if ( !NT_SUCCESS(errCode) ) { - SetLastError(RtlNtStatusToDosError(errCode)); + SetLastError (RtlNtStatusToDosError (errCode)); + return FALSE; + } + } + else if (!NT_SUCCESS(errCode)) + { + SetLastError (RtlNtStatusToDosError (errCode)); return FALSE; } - if (lpOverlapped) - *lpBytesReturned = lpOverlapped->InternalHigh; - else - *lpBytesReturned = IoStatusBlock->Information; - return TRUE; + + if (lpOverlapped) + *lpBytesReturned = lpOverlapped->InternalHigh; + else + *lpBytesReturned = IoStatusBlock->Information; + + return TRUE; } - -WINBOOL -STDCALL -GetOverlappedResult( - HANDLE hFile, - LPOVERLAPPED lpOverlapped, - LPDWORD lpNumberOfBytesTransferred, - WINBOOL bWait - ) +WINBOOL +STDCALL +GetOverlappedResult ( + HANDLE hFile, + LPOVERLAPPED lpOverlapped, + LPDWORD lpNumberOfBytesTransferred, + WINBOOL bWait + ) { DWORD WaitStatus; - if ( lpOverlapped == NULL ) { + if (lpOverlapped == NULL) + { SetLastError(RtlNtStatusToDosError(STATUS_INVALID_PARAMETER)); return FALSE; } - if ( lpOverlapped ->Internal == STATUS_PENDING) { - if ( lpNumberOfBytesTransferred == 0 ) { - SetLastError(RtlNtStatusToDosError(STATUS_PENDING)); + + if (lpOverlapped ->Internal == STATUS_PENDING) + { + if (lpNumberOfBytesTransferred == 0) + { + SetLastError (RtlNtStatusToDosError (STATUS_PENDING)); return FALSE; - } - else if ( bWait == TRUE ) { - if ( lpOverlapped->hEvent != NULL ) { - WaitStatus = WaitForSingleObject(lpOverlapped->hEvent,-1); - if ( WaitStatus == STATUS_TIMEOUT ) { - SetLastError(ERROR_IO_INCOMPLETE); - return FALSE; - } + } + else if (bWait == TRUE) + { + if (lpOverlapped->hEvent != NULL) + { + WaitStatus = WaitForSingleObject (lpOverlapped->hEvent, + -1); + if (WaitStatus == STATUS_TIMEOUT) + { + SetLastError (ERROR_IO_INCOMPLETE); + return FALSE; + } else - return GetOverlappedResult(hFile,lpOverlapped,lpNumberOfBytesTransferred,FALSE); - - } + return GetOverlappedResult (hFile, + lpOverlapped, + lpNumberOfBytesTransferred, + FALSE); + } } } - *lpNumberOfBytesTransferred = lpOverlapped->InternalHigh; - if ( lpOverlapped->Internal < 0 ) { - SetLastError(RtlNtStatusToDosError(lpOverlapped->Internal)); - return FALSE; - } - return TRUE; - + *lpNumberOfBytesTransferred = lpOverlapped->InternalHigh; + if (lpOverlapped->Internal < 0) + { + SetLastError (RtlNtStatusToDosError (lpOverlapped->Internal)); + return FALSE; + } + + return TRUE; } +/* EOF */ diff --git a/reactos/lib/kernel32/file/lfile.c b/reactos/lib/kernel32/file/lfile.c index a2464812614..5bbafbd702d 100644 --- a/reactos/lib/kernel32/file/lfile.c +++ b/reactos/lib/kernel32/file/lfile.c @@ -1,4 +1,4 @@ -/* $Id: lfile.c,v 1.4 1999/08/29 06:59:01 ea Exp $ +/* $Id: lfile.c,v 1.5 2000/03/14 23:09:23 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -15,14 +15,12 @@ #include - - long STDCALL _hread( - HFILE hFile, - LPVOID lpBuffer, - long lBytes + HFILE hFile, + LPVOID lpBuffer, + long lBytes ) { DWORD NumberOfBytesRead; @@ -63,9 +61,9 @@ _lread ( long STDCALL _hwrite ( - HFILE hFile, - LPCSTR lpBuffer, - long lBytes + HFILE hFile, + LPCSTR lpBuffer, + long lBytes ) { DWORD NumberOfBytesWritten; @@ -130,13 +128,11 @@ _lopen ( else if ((iReadWrite & OF_SHARE_DENY_NONE) == OF_SHARE_DENY_NONE) dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; else if ((iReadWrite & OF_SHARE_DENY_READ) == OF_SHARE_DENY_READ) - dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_DELETE; + dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_DELETE; else if ((iReadWrite & OF_SHARE_DENY_WRITE) == OF_SHARE_DENY_WRITE ) - dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE; + dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE; else if ((iReadWrite & OF_SHARE_EXCLUSIVE) == OF_SHARE_EXCLUSIVE) - dwShareMode = 0; - - + dwShareMode = 0; SetLastError(0); return (HFILE) CreateFileA( @@ -146,9 +142,7 @@ _lopen ( NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, - NULL - ); - + NULL); } @@ -178,22 +172,21 @@ _lcreat ( NULL, CREATE_ALWAYS, iAttribute, - NULL - ); + NULL); } int STDCALL _lclose ( - HFILE hFile + HFILE hFile ) { - if ( CloseHandle((HANDLE)hFile) ) + if (CloseHandle ((HANDLE)hFile)) { return 0; } - return -1; + return -1; } @@ -201,17 +194,15 @@ LONG STDCALL _llseek( HFILE hFile, - LONG lOffset, - int iOrigin + LONG lOffset, + int iOrigin ) { - return SetFilePointer( + return SetFilePointer ( (HANDLE) hFile, lOffset, NULL, - (DWORD) iOrigin - ); + (DWORD) iOrigin); } - /* EOF */ diff --git a/reactos/lib/kernel32/file/move.c b/reactos/lib/kernel32/file/move.c index 454967fffbb..6d0f5695bcc 100644 --- a/reactos/lib/kernel32/file/move.c +++ b/reactos/lib/kernel32/file/move.c @@ -1,95 +1,116 @@ -/* +/* $Id: move.c,v 1.3 2000/03/14 23:09:23 ekohl Exp $ + * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/kernel32/file/file.c * PURPOSE: Directory functions * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) - * GetTempFileName is modified from WINE [ Alexandre Juiliard ] * UPDATE HISTORY: * Created 01/11/98 */ -/* FIXME: the large integer manipulations in this file dont handle overflow */ - -/* INCLUDES ****************************************************************/ +/* INCLUDES *****************************************************************/ #include #include -#include -#include -//#define NDEBUG +#define NDEBUG #include + +#define FILE_RENAME_SIZE MAX_PATH +sizeof(FILE_RENAME_INFORMATION) + + /* FUNCTIONS ****************************************************************/ WINBOOL STDCALL -MoveFileA( - LPCSTR lpExistingFileName, - LPCSTR lpNewFileName - ) +MoveFileA ( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName + ) { - return MoveFileExA(lpExistingFileName,lpNewFileName,MOVEFILE_COPY_ALLOWED); + return MoveFileExA (lpExistingFileName, + lpNewFileName, + MOVEFILE_COPY_ALLOWED); } -WINBOOL -STDCALL -MoveFileExA( - LPCSTR lpExistingFileName, - LPCSTR lpNewFileName, - DWORD dwFlags - ) -{ - ULONG i; - WCHAR ExistingFileNameW[MAX_PATH]; - WCHAR NewFileNameW[MAX_PATH]; - - - - i = 0; - while ((*lpExistingFileName)!=0 && i < MAX_PATH) - { - ExistingFileNameW[i] = *lpExistingFileName; - lpExistingFileName++; - i++; - } - ExistingFileNameW[i] = 0; - - i = 0; - while ((*lpNewFileName)!=0 && i < MAX_PATH) - { - NewFileNameW[i] = *lpNewFileName; - lpNewFileName++; - i++; - } - NewFileNameW[i] = 0; - - return MoveFileExW(ExistingFileNameW,NewFileNameW,dwFlags); - -} - - WINBOOL STDCALL -MoveFileW( - LPCWSTR lpExistingFileName, - LPCWSTR lpNewFileName - ) +MoveFileExA ( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName, + DWORD dwFlags + ) { - return MoveFileExW(lpExistingFileName,lpNewFileName,MOVEFILE_COPY_ALLOWED); + UNICODE_STRING ExistingFileNameU; + UNICODE_STRING NewFileNameU; + ANSI_STRING ExistingFileName; + ANSI_STRING NewFileName; + WINBOOL Result; + + RtlInitAnsiString (&ExistingFileName, + (LPSTR)lpExistingFileName); + + RtlInitAnsiString (&NewFileName, + (LPSTR)lpNewFileName); + + /* convert ansi (or oem) string to unicode */ + if (bIsFileApiAnsi) + { + RtlAnsiStringToUnicodeString (&ExistingFileNameU, + &ExistingFileName, + TRUE); + RtlAnsiStringToUnicodeString (&NewFileNameU, + &NewFileName, + TRUE); + } + else + { + RtlOemStringToUnicodeString (&ExistingFileNameU, + &ExistingFileName, + TRUE); + RtlOemStringToUnicodeString (&NewFileNameU, + &NewFileName, + TRUE); + } + + Result = MoveFileExW (ExistingFileNameU.Buffer, + NewFileNameU.Buffer, + dwFlags); + + RtlFreeHeap (RtlGetProcessHeap (), + 0, + ExistingFileNameU.Buffer); + RtlFreeHeap (RtlGetProcessHeap (), + 0, + NewFileNameU.Buffer); + + return Result; } -#define FILE_RENAME_SIZE MAX_PATH +sizeof(FILE_RENAME_INFORMATION) WINBOOL STDCALL -MoveFileExW( - LPCWSTR lpExistingFileName, - LPCWSTR lpNewFileName, - DWORD dwFlags - ) +MoveFileW ( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName + ) +{ + return MoveFileExW (lpExistingFileName, + lpNewFileName, + MOVEFILE_COPY_ALLOWED); +} + + +WINBOOL +STDCALL +MoveFileExW ( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName, + DWORD dwFlags + ) { HANDLE hFile = NULL; IO_STATUS_BLOCK IoStatusBlock; @@ -97,33 +118,40 @@ MoveFileExW( USHORT Buffer[FILE_RENAME_SIZE]; NTSTATUS errCode; - hFile = CreateFileW( - lpExistingFileName, - GENERIC_ALL, - FILE_SHARE_WRITE|FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL - ); - - + hFile = CreateFileW (lpExistingFileName, + GENERIC_ALL, + FILE_SHARE_WRITE|FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); FileRename = (FILE_RENAME_INFORMATION *)Buffer; - if ( ( dwFlags & MOVEFILE_REPLACE_EXISTING ) == MOVEFILE_REPLACE_EXISTING ) + if ((dwFlags & MOVEFILE_REPLACE_EXISTING) == MOVEFILE_REPLACE_EXISTING) FileRename->Replace = TRUE; else FileRename->Replace = FALSE; - FileRename->FileNameLength = lstrlenW(lpNewFileName); - memcpy(FileRename->FileName,lpNewFileName,min(FileRename->FileNameLength,MAX_PATH)); + FileRename->FileNameLength = wcslen (lpNewFileName); + memcpy (FileRename->FileName, + lpNewFileName, + min(FileRename->FileNameLength, MAX_PATH)); - errCode = NtSetInformationFile(hFile,&IoStatusBlock,FileRename, FILE_RENAME_SIZE, FileRenameInformation); - if ( !NT_SUCCESS(errCode) ) { - if ( CopyFileW(lpExistingFileName,lpNewFileName,FileRename->Replace) ) - DeleteFileW(lpExistingFileName); + errCode = NtSetInformationFile (hFile, + &IoStatusBlock, + FileRename, + FILE_RENAME_SIZE, + FileRenameInformation); + if (!NT_SUCCESS(errCode)) + { + if (CopyFileW (lpExistingFileName, + lpNewFileName, + FileRename->Replace)) + DeleteFileW (lpExistingFileName); } CloseHandle(hFile); return TRUE; } + +/* EOF */