| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fxcrt/fxcrt_windows.h" | 7 #include "core/fxcrt/fxcrt_windows.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_string.h" | 9 #include "core/fxcrt/include/fx_string.h" |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 extern "C" { | 32 extern "C" { |
| 33 #endif | 33 #endif |
| 34 WINBASEAPI BOOL WINAPI GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize); | 34 WINBASEAPI BOOL WINAPI GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize); |
| 35 WINBASEAPI BOOL WINAPI SetFilePointerEx(HANDLE hFile, | 35 WINBASEAPI BOOL WINAPI SetFilePointerEx(HANDLE hFile, |
| 36 LARGE_INTEGER liDistanceToMove, | 36 LARGE_INTEGER liDistanceToMove, |
| 37 PLARGE_INTEGER lpNewFilePointer, | 37 PLARGE_INTEGER lpNewFilePointer, |
| 38 DWORD dwMoveMethod); | 38 DWORD dwMoveMethod); |
| 39 #ifdef __cplusplus | 39 #ifdef __cplusplus |
| 40 } | 40 } |
| 41 #endif | 41 #endif |
| 42 CFXCRT_FileAccess_Win64::CFXCRT_FileAccess_Win64() : m_hFile(NULL) {} | 42 CFXCRT_FileAccess_Win64::CFXCRT_FileAccess_Win64() : m_hFile(nullptr) {} |
| 43 CFXCRT_FileAccess_Win64::~CFXCRT_FileAccess_Win64() { | 43 CFXCRT_FileAccess_Win64::~CFXCRT_FileAccess_Win64() { |
| 44 Close(); | 44 Close(); |
| 45 } | 45 } |
| 46 FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName, | 46 FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName, |
| 47 uint32_t dwMode) { | 47 uint32_t dwMode) { |
| 48 if (m_hFile) { | 48 if (m_hFile) { |
| 49 return FALSE; | 49 return FALSE; |
| 50 } | 50 } |
| 51 uint32_t dwAccess, dwShare, dwCreation; | 51 uint32_t dwAccess, dwShare, dwCreation; |
| 52 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); | 52 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); |
| 53 m_hFile = ::CreateFileA(fileName.c_str(), dwAccess, dwShare, NULL, dwCreation, | 53 m_hFile = ::CreateFileA(fileName.c_str(), dwAccess, dwShare, nullptr, |
| 54 FILE_ATTRIBUTE_NORMAL, NULL); | 54 dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 55 if (m_hFile == INVALID_HANDLE_VALUE) { | 55 if (m_hFile == INVALID_HANDLE_VALUE) |
| 56 m_hFile = NULL; | 56 m_hFile = nullptr; |
| 57 } | 57 return !!m_hFile; |
| 58 return m_hFile != NULL; | |
| 59 } | 58 } |
| 60 FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName, | 59 FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName, |
| 61 uint32_t dwMode) { | 60 uint32_t dwMode) { |
| 62 if (m_hFile) { | 61 if (m_hFile) { |
| 63 return FALSE; | 62 return FALSE; |
| 64 } | 63 } |
| 65 uint32_t dwAccess, dwShare, dwCreation; | 64 uint32_t dwAccess, dwShare, dwCreation; |
| 66 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); | 65 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); |
| 67 m_hFile = ::CreateFileW((LPCWSTR)fileName.c_str(), dwAccess, dwShare, NULL, | 66 m_hFile = ::CreateFileW((LPCWSTR)fileName.c_str(), dwAccess, dwShare, nullptr, |
| 68 dwCreation, FILE_ATTRIBUTE_NORMAL, NULL); | 67 dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 69 if (m_hFile == INVALID_HANDLE_VALUE) { | 68 if (m_hFile == INVALID_HANDLE_VALUE) |
| 70 m_hFile = NULL; | 69 m_hFile = nullptr; |
| 71 } | 70 return !!m_hFile; |
| 72 return m_hFile != NULL; | |
| 73 } | 71 } |
| 74 void CFXCRT_FileAccess_Win64::Close() { | 72 void CFXCRT_FileAccess_Win64::Close() { |
| 75 if (!m_hFile) { | 73 if (!m_hFile) { |
| 76 return; | 74 return; |
| 77 } | 75 } |
| 78 ::CloseHandle(m_hFile); | 76 ::CloseHandle(m_hFile); |
| 79 m_hFile = NULL; | 77 m_hFile = nullptr; |
| 80 } | 78 } |
| 81 FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const { | 79 FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const { |
| 82 if (!m_hFile) { | 80 if (!m_hFile) { |
| 83 return 0; | 81 return 0; |
| 84 } | 82 } |
| 85 LARGE_INTEGER size = {}; | 83 LARGE_INTEGER size = {}; |
| 86 if (!::GetFileSizeEx(m_hFile, &size)) { | 84 if (!::GetFileSizeEx(m_hFile, &size)) { |
| 87 return 0; | 85 return 0; |
| 88 } | 86 } |
| 89 return (FX_FILESIZE)size.QuadPart; | 87 return (FX_FILESIZE)size.QuadPart; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 109 if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_BEGIN)) { | 107 if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_BEGIN)) { |
| 110 return (FX_FILESIZE)-1; | 108 return (FX_FILESIZE)-1; |
| 111 } | 109 } |
| 112 return (FX_FILESIZE)newPos.QuadPart; | 110 return (FX_FILESIZE)newPos.QuadPart; |
| 113 } | 111 } |
| 114 size_t CFXCRT_FileAccess_Win64::Read(void* pBuffer, size_t szBuffer) { | 112 size_t CFXCRT_FileAccess_Win64::Read(void* pBuffer, size_t szBuffer) { |
| 115 if (!m_hFile) { | 113 if (!m_hFile) { |
| 116 return 0; | 114 return 0; |
| 117 } | 115 } |
| 118 size_t szRead = 0; | 116 size_t szRead = 0; |
| 119 if (!::ReadFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szRead, NULL)) { | 117 if (!::ReadFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szRead, |
| 118 nullptr)) { |
| 120 return 0; | 119 return 0; |
| 121 } | 120 } |
| 122 return szRead; | 121 return szRead; |
| 123 } | 122 } |
| 124 size_t CFXCRT_FileAccess_Win64::Write(const void* pBuffer, size_t szBuffer) { | 123 size_t CFXCRT_FileAccess_Win64::Write(const void* pBuffer, size_t szBuffer) { |
| 125 if (!m_hFile) { | 124 if (!m_hFile) { |
| 126 return 0; | 125 return 0; |
| 127 } | 126 } |
| 128 size_t szWrite = 0; | 127 size_t szWrite = 0; |
| 129 if (!::WriteFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szWrite, | 128 if (!::WriteFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szWrite, |
| 130 NULL)) { | 129 nullptr)) { |
| 131 return 0; | 130 return 0; |
| 132 } | 131 } |
| 133 return szWrite; | 132 return szWrite; |
| 134 } | 133 } |
| 135 size_t CFXCRT_FileAccess_Win64::ReadPos(void* pBuffer, | 134 size_t CFXCRT_FileAccess_Win64::ReadPos(void* pBuffer, |
| 136 size_t szBuffer, | 135 size_t szBuffer, |
| 137 FX_FILESIZE pos) { | 136 FX_FILESIZE pos) { |
| 138 if (!m_hFile) { | 137 if (!m_hFile) { |
| 139 return 0; | 138 return 0; |
| 140 } | 139 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 163 } | 162 } |
| 164 return ::FlushFileBuffers(m_hFile); | 163 return ::FlushFileBuffers(m_hFile); |
| 165 } | 164 } |
| 166 FX_BOOL CFXCRT_FileAccess_Win64::Truncate(FX_FILESIZE szFile) { | 165 FX_BOOL CFXCRT_FileAccess_Win64::Truncate(FX_FILESIZE szFile) { |
| 167 if (SetPosition(szFile) == (FX_FILESIZE)-1) { | 166 if (SetPosition(szFile) == (FX_FILESIZE)-1) { |
| 168 return FALSE; | 167 return FALSE; |
| 169 } | 168 } |
| 170 return ::SetEndOfFile(m_hFile); | 169 return ::SetEndOfFile(m_hFile); |
| 171 } | 170 } |
| 172 #endif | 171 #endif |
| OLD | NEW |