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_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
8 #include "fxcrt_posix.h" | 8 #include "fxcrt_posix.h" |
9 | 9 |
10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_AP
PLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_AP
PLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 } | 28 } |
29 CFXCRT_FileAccess_Posix::CFXCRT_FileAccess_Posix() | 29 CFXCRT_FileAccess_Posix::CFXCRT_FileAccess_Posix() |
30 : m_nFD(-1) | 30 : m_nFD(-1) |
31 { | 31 { |
32 } | 32 } |
33 CFXCRT_FileAccess_Posix::~CFXCRT_FileAccess_Posix() | 33 CFXCRT_FileAccess_Posix::~CFXCRT_FileAccess_Posix() |
34 { | 34 { |
35 Close(); | 35 Close(); |
36 } | 36 } |
37 FX_BOOL CFXCRT_FileAccess_Posix::Open(const CFX_ByteStringC& fileName, FX_DWORD
dwMode) | 37 bool CFXCRT_FileAccess_Posix::Open(const CFX_ByteStringC& fileName, FX_DWORD dwM
ode) |
38 { | 38 { |
39 if (m_nFD > -1) { | 39 if (m_nFD > -1) { |
40 return FALSE; | 40 return false; |
41 } | 41 } |
42 int32_t nFlags, nMasks; | 42 int32_t nFlags, nMasks; |
43 FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); | 43 FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); |
44 m_nFD = open(fileName.GetCStr(), nFlags, nMasks); | 44 m_nFD = open(fileName.GetCStr(), nFlags, nMasks); |
45 return m_nFD > -1; | 45 return m_nFD > -1; |
46 } | 46 } |
47 FX_BOOL CFXCRT_FileAccess_Posix::Open(const CFX_WideStringC& fileName, FX_DWORD
dwMode) | 47 bool CFXCRT_FileAccess_Posix::Open(const CFX_WideStringC& fileName, FX_DWORD dwM
ode) |
48 { | 48 { |
49 return Open(FX_UTF8Encode(fileName), dwMode); | 49 return Open(FX_UTF8Encode(fileName), dwMode); |
50 } | 50 } |
51 void CFXCRT_FileAccess_Posix::Close() | 51 void CFXCRT_FileAccess_Posix::Close() |
52 { | 52 { |
53 if (m_nFD < 0) { | 53 if (m_nFD < 0) { |
54 return; | 54 return; |
55 } | 55 } |
56 close(m_nFD); | 56 close(m_nFD); |
57 m_nFD = -1; | 57 m_nFD = -1; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 size_t CFXCRT_FileAccess_Posix::WritePos(const void* pBuffer, size_t szBuffer, F
X_FILESIZE pos) | 114 size_t CFXCRT_FileAccess_Posix::WritePos(const void* pBuffer, size_t szBuffer, F
X_FILESIZE pos) |
115 { | 115 { |
116 if (m_nFD < 0) { | 116 if (m_nFD < 0) { |
117 return 0; | 117 return 0; |
118 } | 118 } |
119 if (SetPosition(pos) == (FX_FILESIZE) - 1) { | 119 if (SetPosition(pos) == (FX_FILESIZE) - 1) { |
120 return 0; | 120 return 0; |
121 } | 121 } |
122 return Write(pBuffer, szBuffer); | 122 return Write(pBuffer, szBuffer); |
123 } | 123 } |
124 FX_BOOL CFXCRT_FileAccess_Posix::Flush() | 124 bool CFXCRT_FileAccess_Posix::Flush() |
125 { | 125 { |
126 if (m_nFD < 0) { | 126 if (m_nFD < 0) { |
127 return FALSE; | 127 return false; |
128 } | 128 } |
129 return fsync(m_nFD) > -1; | 129 return fsync(m_nFD) > -1; |
130 } | 130 } |
131 FX_BOOL CFXCRT_FileAccess_Posix::Truncate(FX_FILESIZE szFile) | 131 bool CFXCRT_FileAccess_Posix::Truncate(FX_FILESIZE szFile) |
132 { | 132 { |
133 if (m_nFD < 0) { | 133 if (m_nFD < 0) { |
134 return FALSE; | 134 return false; |
135 } | 135 } |
136 return !ftruncate(m_nFD, szFile); | 136 return !ftruncate(m_nFD, szFile); |
137 } | 137 } |
138 FX_BOOL FX_File_Exist(const CFX_ByteStringC& fileName) | 138 bool FX_File_Exist(const CFX_ByteStringC& fileName) |
139 { | 139 { |
140 return access(fileName.GetCStr(), F_OK) > -1; | 140 return access(fileName.GetCStr(), F_OK) > -1; |
141 } | 141 } |
142 FX_BOOL FX_File_Exist(const CFX_WideStringC& fileName) | 142 bool FX_File_Exist(const CFX_WideStringC& fileName) |
143 { | 143 { |
144 return FX_File_Exist(FX_UTF8Encode(fileName)); | 144 return FX_File_Exist(FX_UTF8Encode(fileName)); |
145 } | 145 } |
146 FX_BOOL FX_File_Delete(const CFX_ByteStringC& fileName) | 146 bool FX_File_Delete(const CFX_ByteStringC& fileName) |
147 { | 147 { |
148 return remove(fileName.GetCStr()) > -1; | 148 return remove(fileName.GetCStr()) > -1; |
149 } | 149 } |
150 FX_BOOL FX_File_Delete(const CFX_WideStringC& fileName) | 150 bool FX_File_Delete(const CFX_WideStringC& fileName) |
151 { | 151 { |
152 return FX_File_Delete(FX_UTF8Encode(fileName)); | 152 return FX_File_Delete(FX_UTF8Encode(fileName)); |
153 } | 153 } |
154 FX_BOOL FX_File_Copy(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC&
fileNameDst) | 154 bool FX_File_Copy(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fil
eNameDst) |
155 { | 155 { |
156 CFXCRT_FileAccess_Posix src, dst; | 156 CFXCRT_FileAccess_Posix src, dst; |
157 if (!src.Open(fileNameSrc, FX_FILEMODE_ReadOnly)) { | 157 if (!src.Open(fileNameSrc, FX_FILEMODE_ReadOnly)) { |
158 return FALSE; | 158 return false; |
159 } | 159 } |
160 FX_FILESIZE size = src.GetSize(); | 160 FX_FILESIZE size = src.GetSize(); |
161 if (!size) { | 161 if (!size) { |
162 return FALSE; | 162 return false; |
163 } | 163 } |
164 if (!dst.Open(fileNameDst, FX_FILEMODE_Truncate)) { | 164 if (!dst.Open(fileNameDst, FX_FILEMODE_Truncate)) { |
165 return FALSE; | 165 return false; |
166 } | 166 } |
167 size_t num = 0; | 167 size_t num = 0; |
168 uint8_t* pBuffer = FX_Alloc(uint8_t, 32768); | 168 uint8_t* pBuffer = FX_Alloc(uint8_t, 32768); |
169 num = src.Read(pBuffer, 32768); | 169 num = src.Read(pBuffer, 32768); |
170 while (num) { | 170 while (num) { |
171 if (dst.Write(pBuffer, num) != num) { | 171 if (dst.Write(pBuffer, num) != num) { |
172 break; | 172 break; |
173 } | 173 } |
174 num = src.Read(pBuffer, 32768); | 174 num = src.Read(pBuffer, 32768); |
175 } | 175 } |
176 FX_Free(pBuffer); | 176 FX_Free(pBuffer); |
177 return TRUE; | 177 return true; |
178 } | 178 } |
179 FX_BOOL FX_File_Copy(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC&
fileNameDst) | 179 bool FX_File_Copy(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fil
eNameDst) |
180 { | 180 { |
181 return FX_File_Copy(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); | 181 return FX_File_Copy(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); |
182 } | 182 } |
183 FX_BOOL FX_File_Move(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC&
fileNameDst) | 183 bool FX_File_Move(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fil
eNameDst) |
184 { | 184 { |
185 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); | 185 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); |
186 } | 186 } |
187 FX_BOOL FX_File_Move(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC&
fileNameDst) | 187 bool FX_File_Move(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fil
eNameDst) |
188 { | 188 { |
189 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); | 189 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); |
190 } | 190 } |
191 #endif | 191 #endif |
OLD | NEW |