Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3436)

Unified Diff: core/fxcrt/fxcrt_windows.cpp

Issue 2450183003: Fix some FX_BOOL / int noise in fxcrt. (Closed)
Patch Set: moar Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fxcrt/fxcrt_windows.h ('k') | core/fxcrt/xml_int.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fxcrt_windows.cpp
diff --git a/core/fxcrt/fxcrt_windows.cpp b/core/fxcrt/fxcrt_windows.cpp
index ec16373f02dafa3b3d57c97dd13d94de010d2e8a..87bbe96a5c69c117b9a521b26b7e389bc0f8e174 100644
--- a/core/fxcrt/fxcrt_windows.cpp
+++ b/core/fxcrt/fxcrt_windows.cpp
@@ -28,6 +28,7 @@ void FXCRT_Windows_GetFileMode(uint32_t dwMode,
dwCreation = OPEN_EXISTING;
}
}
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -39,80 +40,91 @@ WINBASEAPI BOOL WINAPI SetFilePointerEx(HANDLE hFile,
#ifdef __cplusplus
}
#endif
+
CFXCRT_FileAccess_Win64::CFXCRT_FileAccess_Win64() : m_hFile(nullptr) {}
+
CFXCRT_FileAccess_Win64::~CFXCRT_FileAccess_Win64() {
Close();
}
-FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName,
- uint32_t dwMode) {
- if (m_hFile) {
+
+bool CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName,
+ uint32_t dwMode) {
+ if (m_hFile)
return FALSE;
- }
+
uint32_t dwAccess, dwShare, dwCreation;
FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation);
m_hFile = ::CreateFileA(fileName.c_str(), dwAccess, dwShare, nullptr,
dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr);
if (m_hFile == INVALID_HANDLE_VALUE)
m_hFile = nullptr;
+
return !!m_hFile;
}
-FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName,
- uint32_t dwMode) {
- if (m_hFile) {
+
+bool CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName,
+ uint32_t dwMode) {
+ if (m_hFile)
return FALSE;
- }
+
uint32_t dwAccess, dwShare, dwCreation;
FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation);
m_hFile = ::CreateFileW((LPCWSTR)fileName.c_str(), dwAccess, dwShare, nullptr,
dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr);
if (m_hFile == INVALID_HANDLE_VALUE)
m_hFile = nullptr;
+
return !!m_hFile;
}
+
void CFXCRT_FileAccess_Win64::Close() {
- if (!m_hFile) {
+ if (!m_hFile)
return;
- }
+
::CloseHandle(m_hFile);
m_hFile = nullptr;
}
+
FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const {
- if (!m_hFile) {
+ if (!m_hFile)
return 0;
- }
+
LARGE_INTEGER size = {};
- if (!::GetFileSizeEx(m_hFile, &size)) {
+ if (!::GetFileSizeEx(m_hFile, &size))
return 0;
- }
+
return (FX_FILESIZE)size.QuadPart;
}
+
FX_FILESIZE CFXCRT_FileAccess_Win64::GetPosition() const {
- if (!m_hFile) {
+ if (!m_hFile)
return (FX_FILESIZE)-1;
- }
+
LARGE_INTEGER dist = {};
LARGE_INTEGER newPos = {};
- if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_CURRENT)) {
+ if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_CURRENT))
return (FX_FILESIZE)-1;
- }
+
return (FX_FILESIZE)newPos.QuadPart;
}
+
FX_FILESIZE CFXCRT_FileAccess_Win64::SetPosition(FX_FILESIZE pos) {
- if (!m_hFile) {
+ if (!m_hFile)
return (FX_FILESIZE)-1;
- }
+
LARGE_INTEGER dist;
dist.QuadPart = pos;
LARGE_INTEGER newPos = {};
- if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_BEGIN)) {
+ if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_BEGIN))
return (FX_FILESIZE)-1;
- }
+
return (FX_FILESIZE)newPos.QuadPart;
}
+
size_t CFXCRT_FileAccess_Win64::Read(void* pBuffer, size_t szBuffer) {
- if (!m_hFile) {
+ if (!m_hFile)
return 0;
- }
+
size_t szRead = 0;
if (!::ReadFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szRead,
nullptr)) {
@@ -120,10 +132,11 @@ size_t CFXCRT_FileAccess_Win64::Read(void* pBuffer, size_t szBuffer) {
}
return szRead;
}
+
size_t CFXCRT_FileAccess_Win64::Write(const void* pBuffer, size_t szBuffer) {
- if (!m_hFile) {
+ if (!m_hFile)
return 0;
- }
+
size_t szWrite = 0;
if (!::WriteFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szWrite,
nullptr)) {
@@ -131,20 +144,22 @@ size_t CFXCRT_FileAccess_Win64::Write(const void* pBuffer, size_t szBuffer) {
}
return szWrite;
}
+
size_t CFXCRT_FileAccess_Win64::ReadPos(void* pBuffer,
size_t szBuffer,
FX_FILESIZE pos) {
- if (!m_hFile) {
+ if (!m_hFile)
return 0;
- }
- if (pos >= GetSize()) {
+
+ if (pos >= GetSize())
return 0;
- }
- if (SetPosition(pos) == (FX_FILESIZE)-1) {
+
+ if (SetPosition(pos) == (FX_FILESIZE)-1)
return 0;
- }
+
return Read(pBuffer, szBuffer);
}
+
size_t CFXCRT_FileAccess_Win64::WritePos(const void* pBuffer,
size_t szBuffer,
FX_FILESIZE pos) {
@@ -156,16 +171,18 @@ size_t CFXCRT_FileAccess_Win64::WritePos(const void* pBuffer,
}
return Write(pBuffer, szBuffer);
}
-FX_BOOL CFXCRT_FileAccess_Win64::Flush() {
- if (!m_hFile) {
- return FALSE;
- }
- return ::FlushFileBuffers(m_hFile);
+
+bool CFXCRT_FileAccess_Win64::Flush() {
+ if (!m_hFile)
+ return false;
+
+ return !!::FlushFileBuffers(m_hFile);
}
-FX_BOOL CFXCRT_FileAccess_Win64::Truncate(FX_FILESIZE szFile) {
- if (SetPosition(szFile) == (FX_FILESIZE)-1) {
- return FALSE;
- }
- return ::SetEndOfFile(m_hFile);
+
+bool CFXCRT_FileAccess_Win64::Truncate(FX_FILESIZE szFile) {
+ if (SetPosition(szFile) == (FX_FILESIZE)-1)
+ return false;
+
+ return !!::SetEndOfFile(m_hFile);
}
#endif
« no previous file with comments | « core/fxcrt/fxcrt_windows.h ('k') | core/fxcrt/xml_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698