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() | 10 IFXCRT_FileAccess* FXCRT_FileAccess_Create() |
11 { | 11 { |
12 return FX_NEW CFXCRT_FileAccess_Posix; | 12 return FX_NEW CFXCRT_FileAccess_Posix; |
13 } | 13 } |
14 void FXCRT_Posix_GetFileMode(FX_DWORD dwModes, FX_INT32 &nFlags, FX_INT32 &nMask
s) | 14 void FXCRT_Posix_GetFileMode(FX_DWORD dwModes, int32_t &nFlags, int32_t &nMasks) |
15 { | 15 { |
16 nFlags = O_BINARY | O_LARGEFILE; | 16 nFlags = O_BINARY | O_LARGEFILE; |
17 if (dwModes & FX_FILEMODE_ReadOnly) { | 17 if (dwModes & FX_FILEMODE_ReadOnly) { |
18 nFlags |= O_RDONLY; | 18 nFlags |= O_RDONLY; |
19 nMasks = 0; | 19 nMasks = 0; |
20 } else { | 20 } else { |
21 nFlags |= O_RDWR | O_CREAT; | 21 nFlags |= O_RDWR | O_CREAT; |
22 if (dwModes & FX_FILEMODE_Truncate) { | 22 if (dwModes & FX_FILEMODE_Truncate) { |
23 nFlags |= O_TRUNC; | 23 nFlags |= O_TRUNC; |
24 } | 24 } |
25 nMasks = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; | 25 nMasks = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
26 } | 26 } |
27 } | 27 } |
28 CFXCRT_FileAccess_Posix::CFXCRT_FileAccess_Posix() | 28 CFXCRT_FileAccess_Posix::CFXCRT_FileAccess_Posix() |
29 : m_nFD(-1) | 29 : m_nFD(-1) |
30 { | 30 { |
31 } | 31 } |
32 CFXCRT_FileAccess_Posix::~CFXCRT_FileAccess_Posix() | 32 CFXCRT_FileAccess_Posix::~CFXCRT_FileAccess_Posix() |
33 { | 33 { |
34 Close(); | 34 Close(); |
35 } | 35 } |
36 FX_BOOL CFXCRT_FileAccess_Posix::Open(FX_BSTR fileName, FX_DWORD dwMode) | 36 FX_BOOL CFXCRT_FileAccess_Posix::Open(FX_BSTR fileName, FX_DWORD dwMode) |
37 { | 37 { |
38 if (m_nFD > -1) { | 38 if (m_nFD > -1) { |
39 return FALSE; | 39 return FALSE; |
40 } | 40 } |
41 FX_INT32 nFlags, nMasks; | 41 int32_t nFlags, nMasks; |
42 FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); | 42 FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); |
43 m_nFD = open(fileName.GetCStr(), nFlags, nMasks); | 43 m_nFD = open(fileName.GetCStr(), nFlags, nMasks); |
44 return m_nFD > -1; | 44 return m_nFD > -1; |
45 } | 45 } |
46 FX_BOOL CFXCRT_FileAccess_Posix::Open(FX_WSTR fileName, FX_DWORD dwMode) | 46 FX_BOOL CFXCRT_FileAccess_Posix::Open(FX_WSTR fileName, FX_DWORD dwMode) |
47 { | 47 { |
48 return Open(FX_UTF8Encode(fileName), dwMode); | 48 return Open(FX_UTF8Encode(fileName), dwMode); |
49 } | 49 } |
50 void CFXCRT_FileAccess_Posix::Close() | 50 void CFXCRT_FileAccess_Posix::Close() |
51 { | 51 { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return FALSE; | 157 return FALSE; |
158 } | 158 } |
159 FX_FILESIZE size = src.GetSize(); | 159 FX_FILESIZE size = src.GetSize(); |
160 if (!size) { | 160 if (!size) { |
161 return FALSE; | 161 return FALSE; |
162 } | 162 } |
163 if (!dst.Open(fileNameDst, FX_FILEMODE_Truncate)) { | 163 if (!dst.Open(fileNameDst, FX_FILEMODE_Truncate)) { |
164 return FALSE; | 164 return FALSE; |
165 } | 165 } |
166 size_t num = 0; | 166 size_t num = 0; |
167 FX_LPBYTE pBuffer = FX_Alloc(FX_BYTE, 32768); | 167 FX_LPBYTE pBuffer = FX_Alloc(uint8_t, 32768); |
168 num = src.Read(pBuffer, 32768); | 168 num = src.Read(pBuffer, 32768); |
169 while (num) { | 169 while (num) { |
170 if (dst.Write(pBuffer, num) != num) { | 170 if (dst.Write(pBuffer, num) != num) { |
171 break; | 171 break; |
172 } | 172 } |
173 num = src.Read(pBuffer, 32768); | 173 num = src.Read(pBuffer, 32768); |
174 } | 174 } |
175 FX_Free(pBuffer); | 175 FX_Free(pBuffer); |
176 return TRUE; | 176 return TRUE; |
177 } | 177 } |
178 FX_BOOL FX_File_Copy(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) | 178 FX_BOOL FX_File_Copy(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) |
179 { | 179 { |
180 return FX_File_Copy(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); | 180 return FX_File_Copy(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); |
181 } | 181 } |
182 FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) | 182 FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) |
183 { | 183 { |
184 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); | 184 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); |
185 } | 185 } |
186 FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) | 186 FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) |
187 { | 187 { |
188 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); | 188 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); |
189 } | 189 } |
190 #endif | 190 #endif |
OLD | NEW |