| 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_platforms.h" | 7 #include "core/fxcrt/fxcrt_platforms.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_basic.h" | 9 #include "core/fxcrt/include/fx_basic.h" |
| 10 | 10 |
| 11 #if (_FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ && \ | 11 #if (_FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ && \ |
| 12 _FXM_PLATFORM_ != _FXM_PLATFORM_LINUX_ && \ | 12 _FXM_PLATFORM_ != _FXM_PLATFORM_LINUX_ && \ |
| 13 _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ && \ | 13 _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ && \ |
| 14 _FXM_PLATFORM_ != _FXM_PLATFORM_ANDROID_) | 14 _FXM_PLATFORM_ != _FXM_PLATFORM_ANDROID_) |
| 15 IFXCRT_FileAccess* FXCRT_FileAccess_Create() { | 15 IFXCRT_FileAccess* FXCRT_FileAccess_Create() { |
| 16 return new CFXCRT_FileAccess_CRT; | 16 return new CFXCRT_FileAccess_CRT; |
| 17 } | 17 } |
| 18 void FXCRT_GetFileModeString(FX_DWORD dwModes, CFX_ByteString& bsMode) { | 18 void FXCRT_GetFileModeString(uint32_t dwModes, CFX_ByteString& bsMode) { |
| 19 if (dwModes & FX_FILEMODE_ReadOnly) { | 19 if (dwModes & FX_FILEMODE_ReadOnly) { |
| 20 bsMode = "rb"; | 20 bsMode = "rb"; |
| 21 } else if (dwModes & FX_FILEMODE_Truncate) { | 21 } else if (dwModes & FX_FILEMODE_Truncate) { |
| 22 bsMode = "w+b"; | 22 bsMode = "w+b"; |
| 23 } else { | 23 } else { |
| 24 bsMode = "a+b"; | 24 bsMode = "a+b"; |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 void FXCRT_GetFileModeString(FX_DWORD dwModes, CFX_WideString& wsMode) { | 27 void FXCRT_GetFileModeString(uint32_t dwModes, CFX_WideString& wsMode) { |
| 28 if (dwModes & FX_FILEMODE_ReadOnly) { | 28 if (dwModes & FX_FILEMODE_ReadOnly) { |
| 29 wsMode = FX_WSTRC(L"rb"); | 29 wsMode = FX_WSTRC(L"rb"); |
| 30 } else if (dwModes & FX_FILEMODE_Truncate) { | 30 } else if (dwModes & FX_FILEMODE_Truncate) { |
| 31 wsMode = FX_WSTRC(L"w+b"); | 31 wsMode = FX_WSTRC(L"w+b"); |
| 32 } else { | 32 } else { |
| 33 wsMode = FX_WSTRC(L"a+b"); | 33 wsMode = FX_WSTRC(L"a+b"); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 CFXCRT_FileAccess_CRT::CFXCRT_FileAccess_CRT() : m_hFile(NULL) {} | 36 CFXCRT_FileAccess_CRT::CFXCRT_FileAccess_CRT() : m_hFile(NULL) {} |
| 37 CFXCRT_FileAccess_CRT::~CFXCRT_FileAccess_CRT() { | 37 CFXCRT_FileAccess_CRT::~CFXCRT_FileAccess_CRT() { |
| 38 Close(); | 38 Close(); |
| 39 } | 39 } |
| 40 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_ByteStringC& fileName, | 40 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_ByteStringC& fileName, |
| 41 FX_DWORD dwMode) { | 41 uint32_t dwMode) { |
| 42 if (m_hFile) { | 42 if (m_hFile) { |
| 43 return FALSE; | 43 return FALSE; |
| 44 } | 44 } |
| 45 CFX_ByteString strMode; | 45 CFX_ByteString strMode; |
| 46 FXCRT_GetFileModeString(dwMode, strMode); | 46 FXCRT_GetFileModeString(dwMode, strMode); |
| 47 m_hFile = FXSYS_fopen(fileName.GetCStr(), strMode.c_str()); | 47 m_hFile = FXSYS_fopen(fileName.GetCStr(), strMode.c_str()); |
| 48 return m_hFile != NULL; | 48 return m_hFile != NULL; |
| 49 } | 49 } |
| 50 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_WideStringC& fileName, | 50 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_WideStringC& fileName, |
| 51 FX_DWORD dwMode) { | 51 uint32_t dwMode) { |
| 52 if (m_hFile) { | 52 if (m_hFile) { |
| 53 return FALSE; | 53 return FALSE; |
| 54 } | 54 } |
| 55 CFX_WideString strMode; | 55 CFX_WideString strMode; |
| 56 FXCRT_GetFileModeString(dwMode, strMode); | 56 FXCRT_GetFileModeString(dwMode, strMode); |
| 57 m_hFile = FXSYS_wfopen(fileName.GetPtr(), strMode.c_str()); | 57 m_hFile = FXSYS_wfopen(fileName.GetPtr(), strMode.c_str()); |
| 58 return m_hFile != NULL; | 58 return m_hFile != NULL; |
| 59 } | 59 } |
| 60 void CFXCRT_FileAccess_CRT::Close() { | 60 void CFXCRT_FileAccess_CRT::Close() { |
| 61 if (!m_hFile) { | 61 if (!m_hFile) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 FX_BOOL CFXCRT_FileAccess_CRT::Flush() { | 123 FX_BOOL CFXCRT_FileAccess_CRT::Flush() { |
| 124 if (!m_hFile) { | 124 if (!m_hFile) { |
| 125 return FALSE; | 125 return FALSE; |
| 126 } | 126 } |
| 127 return !FXSYS_fflush(m_hFile); | 127 return !FXSYS_fflush(m_hFile); |
| 128 } | 128 } |
| 129 FX_BOOL CFXCRT_FileAccess_CRT::Truncate(FX_FILESIZE szFile) { | 129 FX_BOOL CFXCRT_FileAccess_CRT::Truncate(FX_FILESIZE szFile) { |
| 130 return FALSE; | 130 return FALSE; |
| 131 } | 131 } |
| 132 #endif | 132 #endif |
| OLD | NEW |