Rev 31 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "pch.h"
#pragma hdrstop
#include "OsFile.h"
bool OsFileExists(char *fileName)
{
DWORD dwFileAttributes = GetFileAttributesA(fileName);
return (dwFileAttributes != INVALID_FILE_ATTRIBUTES && !(dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}
bool OsDirectoryExists(char *directory)
{
DWORD dwFileAttributes = GetFileAttributesA(directory);
return (dwFileAttributes != INVALID_FILE_ATTRIBUTES && (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}
HANDLE OsCreateFile(char *fileName,
DWORD desiredAccess,
DWORD shareMode,
DWORD createDisposition,
DWORD flagsAndAttributes,
HANDLE extendedFileType)
{
HANDLE result;
int length = MultiByteToWideChar(CP_UTF8, 0, fileName, -1, NULL, 0);
LPWSTR fileNameW = new wchar_t[length];
MultiByteToWideChar(CP_UTF8, 0, fileName, -1, fileNameW, length);
result = CreateFileW(fileNameW, desiredAccess, shareMode, 0, createDisposition, flagsAndAttributes, extendedFileType);
delete[] fileNameW;
return result;
}
BOOL OsReadFile(HANDLE hFile, void *buffer, DWORD bytesToRead, DWORD *bytesRead)
{
return ReadFile(hFile, buffer, bytesToRead, bytesRead, 0);
}
DWORD OsSetFilePointer(HANDLE hFile, DWORD moveMethod, LONG distanceToMove)
{
DWORD result;
LONG distanceToMoveHigh;
distanceToMoveHigh = HIWORD(distanceToMove);
result = SetFilePointer(hFile, distanceToMove, &distanceToMoveHigh, moveMethod);
if (result == -1)
{
DWORD error = GetLastError(); /* TODO: Do something here? */
result = -1;
}
return result;
}
BOOL OsWriteFile(HANDLE hFile, const void *buffer, DWORD bytesToWrite, DWORD *bytesWritten)
{
return WriteFile(hFile, buffer, bytesToWrite, bytesWritten, 0);
}
void OsCloseFile(HANDLE hFile)
{
CloseHandle(hFile);
}