From 4b150ded0304d052cea5503420cc87ef61553954 Mon Sep 17 00:00:00 2001 From: zilmar Date: Wed, 11 Nov 2015 17:47:22 +1100 Subject: [PATCH] [Project64] Get File Class.cpp to use standard types --- Source/Common/File Class.cpp | 27 +++++++++------------------ Source/Common/File Class.h | 8 ++++---- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/Source/Common/File Class.cpp b/Source/Common/File Class.cpp index 48acd893a..f9eb583eb 100644 --- a/Source/Common/File Class.cpp +++ b/Source/Common/File Class.cpp @@ -82,13 +82,12 @@ bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags) ULONG dwCreateFlag = 0; if (nOpenFlags & modeCreate) { - if (nOpenFlags & modeNoTruncate) - dwCreateFlag = OPEN_ALWAYS; - else - dwCreateFlag = CREATE_ALWAYS; + dwCreateFlag = nOpenFlags & modeNoTruncate == 0 ? OPEN_ALWAYS : CREATE_ALWAYS; } else + { dwCreateFlag = OPEN_EXISTING; + } // attempt file creation HANDLE hFile = ::CreateFile(lpszFileName, dwAccess, dwShareMode, &sa, dwCreateFlag, FILE_ATTRIBUTE_NORMAL, NULL); @@ -140,19 +139,15 @@ bool CFile::Flush() return ::FlushFileBuffers(m_hFile) != 0; } -bool CFile::Write(const void* lpBuf, size_t nCount) +bool CFile::Write(const void* lpBuf, uint32_t nCount) { if (nCount == 0) { return true; // avoid Win32 "null-write" option } - if (nCount > ULONG_MAX) - { - nCount = ULONG_MAX; /* Or should we loop WriteFile() every 2 GB? */ - } - DWORD nWritten = 0; - if (!::WriteFile(m_hFile, lpBuf, (DWORD)nCount, &nWritten, NULL)) + ULONG nWritten = 0; + if (!::WriteFile(m_hFile, lpBuf, nCount, &nWritten, NULL)) { return false; } @@ -165,23 +160,19 @@ bool CFile::Write(const void* lpBuf, size_t nCount) return true; } -size_t CFile::Read(void* lpBuf, size_t nCount) +uint32_t CFile::Read(void* lpBuf, uint32_t nCount) { if (nCount == 0) { return 0; // avoid Win32 "null-read" } - if (nCount > ULONG_MAX) - { - nCount = ULONG_MAX; /* Or should we loop ReadFile() every 2 GB? */ - } DWORD dwRead = 0; - if (!::ReadFile(m_hFile, lpBuf, (DWORD)nCount, &dwRead, NULL)) + if (!::ReadFile(m_hFile, lpBuf, nCount, &dwRead, NULL)) { return 0; } - return (dwRead); + return (uint32_t)dwRead; } long CFile::Seek(long lOff, SeekPosition nFrom) diff --git a/Source/Common/File Class.h b/Source/Common/File Class.h index c61730450..fc734f633 100644 --- a/Source/Common/File Class.h +++ b/Source/Common/File Class.h @@ -40,8 +40,8 @@ public: virtual bool SetLength(uint32_t dwNewLen) = 0; virtual uint32_t GetLength() const = 0; - virtual size_t Read(void* lpBuf, size_t nCount) = 0; - virtual bool Write(const void* lpBuf, size_t nCount) = 0; + virtual uint32_t Read(void* lpBuf, uint32_t nCount) = 0; + virtual bool Write(const void* lpBuf, uint32_t nCount) = 0; virtual bool Flush() = 0; virtual bool Close() = 0; @@ -78,8 +78,8 @@ public: virtual bool SetLength(uint32_t dwNewLen); virtual uint32_t GetLength() const; - virtual size_t Read(void* lpBuf, size_t nCount); - virtual bool Write(const void* lpBuf, size_t nCount); + virtual uint32_t Read(void* lpBuf, uint32_t nCount); + virtual bool Write(const void* lpBuf, uint32_t nCount); virtual bool Flush(); virtual bool Close();