| 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 "../../include/fxcrt/fx_ext.h" | 7 #include "../../include/fxcrt/fx_ext.h" |
| 8 #include "fxcrt_posix.h" | 8 #include "fxcrt_posix.h" |
| 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_AP
PLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_AP
PLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
| 10 IFXCRT_FileAccess* FXCRT_FileAccess_Create(IFX_Allocator* pAllocator) | 10 IFXCRT_FileAccess* FXCRT_FileAccess_Create() |
| 11 { | 11 { |
| 12 if (pAllocator) { | 12 return FX_NEW CFXCRT_FileAccess_Posix; |
| 13 return FX_NewAtAllocator(pAllocator) CFXCRT_FileAccess_Posix(); | |
| 14 } else { | |
| 15 return FX_NEW CFXCRT_FileAccess_Posix; | |
| 16 } | |
| 17 } | 13 } |
| 18 void FXCRT_Posix_GetFileMode(FX_DWORD dwModes, FX_INT32 &nFlags, FX_INT32 &nMask
s) | 14 void FXCRT_Posix_GetFileMode(FX_DWORD dwModes, FX_INT32 &nFlags, FX_INT32 &nMask
s) |
| 19 { | 15 { |
| 20 nFlags = O_BINARY | O_LARGEFILE; | 16 nFlags = O_BINARY | O_LARGEFILE; |
| 21 if (dwModes & FX_FILEMODE_ReadOnly) { | 17 if (dwModes & FX_FILEMODE_ReadOnly) { |
| 22 nFlags |= O_RDONLY; | 18 nFlags |= O_RDONLY; |
| 23 nMasks = 0; | 19 nMasks = 0; |
| 24 } else { | 20 } else { |
| 25 nFlags |= O_RDWR | O_CREAT; | 21 nFlags |= O_RDWR | O_CREAT; |
| 26 if (dwModes & FX_FILEMODE_Truncate) { | 22 if (dwModes & FX_FILEMODE_Truncate) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 return Open(FX_UTF8Encode(fileName), dwMode); | 48 return Open(FX_UTF8Encode(fileName), dwMode); |
| 53 } | 49 } |
| 54 void CFXCRT_FileAccess_Posix::Close() | 50 void CFXCRT_FileAccess_Posix::Close() |
| 55 { | 51 { |
| 56 if (m_nFD < 0) { | 52 if (m_nFD < 0) { |
| 57 return; | 53 return; |
| 58 } | 54 } |
| 59 close(m_nFD); | 55 close(m_nFD); |
| 60 m_nFD = -1; | 56 m_nFD = -1; |
| 61 } | 57 } |
| 62 void CFXCRT_FileAccess_Posix::Release(IFX_Allocator* pAllocator) | 58 void CFXCRT_FileAccess_Posix::Release() |
| 63 { | 59 { |
| 64 if (pAllocator) { | 60 delete this; |
| 65 FX_DeleteAtAllocator(this, pAllocator, CFXCRT_FileAccess_Posix); | |
| 66 } else { | |
| 67 delete this; | |
| 68 } | |
| 69 } | 61 } |
| 70 FX_FILESIZE CFXCRT_FileAccess_Posix::GetSize() const | 62 FX_FILESIZE CFXCRT_FileAccess_Posix::GetSize() const |
| 71 { | 63 { |
| 72 if (m_nFD < 0) { | 64 if (m_nFD < 0) { |
| 73 return 0; | 65 return 0; |
| 74 } | 66 } |
| 75 struct stat s; | 67 struct stat s; |
| 76 FXSYS_memset32(&s, 0, sizeof(s)); | 68 FXSYS_memset32(&s, 0, sizeof(s)); |
| 77 fstat(m_nFD, &s); | 69 fstat(m_nFD, &s); |
| 78 return s.st_size; | 70 return s.st_size; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 184 } |
| 193 FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) | 185 FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) |
| 194 { | 186 { |
| 195 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); | 187 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); |
| 196 } | 188 } |
| 197 FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) | 189 FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) |
| 198 { | 190 { |
| 199 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); | 191 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); |
| 200 } | 192 } |
| 201 #endif | 193 #endif |
| OLD | NEW |