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_platforms.h" | 8 #include "fxcrt_platforms.h" |
9 | 9 |
10 #if (_FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ && _FXM_PLATFORM_ != _FXM_PLATFORM
_LINUX_ && _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ && _FXM_PLATFORM_ != _FXM_PLAT
FORM_ANDROID_) | 10 #if (_FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ && _FXM_PLATFORM_ != _FXM_PLATFORM
_LINUX_ && _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ && _FXM_PLATFORM_ != _FXM_PLAT
FORM_ANDROID_) |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 } | 34 } |
35 CFXCRT_FileAccess_CRT::CFXCRT_FileAccess_CRT() | 35 CFXCRT_FileAccess_CRT::CFXCRT_FileAccess_CRT() |
36 : m_hFile(NULL) | 36 : m_hFile(NULL) |
37 { | 37 { |
38 } | 38 } |
39 CFXCRT_FileAccess_CRT::~CFXCRT_FileAccess_CRT() | 39 CFXCRT_FileAccess_CRT::~CFXCRT_FileAccess_CRT() |
40 { | 40 { |
41 Close(); | 41 Close(); |
42 } | 42 } |
43 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_ByteStringC& fileName, FX_DWORD dw
Mode) | 43 bool CFXCRT_FileAccess_CRT::Open(const CFX_ByteStringC& fileName, FX_DWORD dwMod
e) |
44 { | 44 { |
45 if (m_hFile) { | 45 if (m_hFile) { |
46 return FALSE; | 46 return false; |
47 } | 47 } |
48 CFX_ByteString strMode; | 48 CFX_ByteString strMode; |
49 FXCRT_GetFileModeString(dwMode, strMode); | 49 FXCRT_GetFileModeString(dwMode, strMode); |
50 m_hFile = FXSYS_fopen(fileName.GetCStr(), strMode.c_str()); | 50 m_hFile = FXSYS_fopen(fileName.GetCStr(), strMode.c_str()); |
51 return m_hFile != NULL; | 51 return m_hFile != NULL; |
52 } | 52 } |
53 FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_WideStringC& fileName, FX_DWORD dw
Mode) | 53 bool CFXCRT_FileAccess_CRT::Open(const CFX_WideStringC& fileName, FX_DWORD dwMod
e) |
54 { | 54 { |
55 if (m_hFile) { | 55 if (m_hFile) { |
56 return FALSE; | 56 return false; |
57 } | 57 } |
58 CFX_WideString strMode; | 58 CFX_WideString strMode; |
59 FXCRT_GetFileModeString(dwMode, strMode); | 59 FXCRT_GetFileModeString(dwMode, strMode); |
60 m_hFile = FXSYS_wfopen(fileName.GetPtr(), strMode.c_str()); | 60 m_hFile = FXSYS_wfopen(fileName.GetPtr(), strMode.c_str()); |
61 return m_hFile != NULL; | 61 return m_hFile != NULL; |
62 } | 62 } |
63 void CFXCRT_FileAccess_CRT::Close() | 63 void CFXCRT_FileAccess_CRT::Close() |
64 { | 64 { |
65 if (!m_hFile) { | 65 if (!m_hFile) { |
66 return; | 66 return; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile); | 121 return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile); |
122 } | 122 } |
123 size_t CFXCRT_FileAccess_CRT::WritePos(const void* pBuffer, size_t szBuffer, FX_
FILESIZE pos) | 123 size_t CFXCRT_FileAccess_CRT::WritePos(const void* pBuffer, size_t szBuffer, FX_
FILESIZE pos) |
124 { | 124 { |
125 if (!m_hFile) { | 125 if (!m_hFile) { |
126 return (FX_FILESIZE) - 1; | 126 return (FX_FILESIZE) - 1; |
127 } | 127 } |
128 FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); | 128 FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); |
129 return FXSYS_fwrite(pBuffer, 1, szBuffer, m_hFile); | 129 return FXSYS_fwrite(pBuffer, 1, szBuffer, m_hFile); |
130 } | 130 } |
131 FX_BOOL CFXCRT_FileAccess_CRT::Flush() | 131 bool CFXCRT_FileAccess_CRT::Flush() |
132 { | 132 { |
133 if (!m_hFile) { | 133 if (!m_hFile) { |
134 return FALSE; | 134 return false; |
135 } | 135 } |
136 return !FXSYS_fflush(m_hFile); | 136 return !FXSYS_fflush(m_hFile); |
137 } | 137 } |
138 FX_BOOL CFXCRT_FileAccess_CRT::Truncate(FX_FILESIZE szFile) | 138 bool CFXCRT_FileAccess_CRT::Truncate(FX_FILESIZE szFile) |
139 { | 139 { |
140 return FALSE; | 140 return false; |
141 } | 141 } |
142 FX_BOOL FX_File_Exist(const CFX_ByteStringC& fileName) | 142 bool FX_File_Exist(const CFX_ByteStringC& fileName) |
143 { | 143 { |
144 return access(fileName.GetCStr(), F_OK) > -1; | 144 return access(fileName.GetCStr(), F_OK) > -1; |
145 } | 145 } |
146 FX_BOOL FX_File_Exist(const CFX_WideStringC& fileName) | 146 bool FX_File_Exist(const CFX_WideStringC& fileName) |
147 { | 147 { |
148 return FX_File_Exist(FX_UTF8Encode(fileName)); | 148 return FX_File_Exist(FX_UTF8Encode(fileName)); |
149 } | 149 } |
150 FX_BOOL FX_File_Delete(const CFX_ByteStringC& fileName) | 150 bool FX_File_Delete(const CFX_ByteStringC& fileName) |
151 { | 151 { |
152 return remove(fileName.GetCStr()) > -1; | 152 return remove(fileName.GetCStr()) > -1; |
153 } | 153 } |
154 FX_BOOL FX_File_Delete(const CFX_WideStringC& fileName) | 154 bool FX_File_Delete(const CFX_WideStringC& fileName) |
155 { | 155 { |
156 return FX_File_Delete(FX_UTF8Encode(fileName)); | 156 return FX_File_Delete(FX_UTF8Encode(fileName)); |
157 } | 157 } |
158 FX_BOOL FX_File_Copy(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC&
fileNameDst) | 158 bool FX_File_Copy(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fil
eNameDst) |
159 { | 159 { |
160 CFXCRT_FileAccess_CRT src, dst; | 160 CFXCRT_FileAccess_CRT src, dst; |
161 if (!src.Open(fileNameSrc, FX_FILEMODE_ReadOnly)) { | 161 if (!src.Open(fileNameSrc, FX_FILEMODE_ReadOnly)) { |
162 return FALSE; | 162 return false; |
163 } | 163 } |
164 FX_FILESIZE size = src.GetSize(); | 164 FX_FILESIZE size = src.GetSize(); |
165 if (!size) { | 165 if (!size) { |
166 return FALSE; | 166 return false; |
167 } | 167 } |
168 if (!dst.Open(fileNameDst, FX_FILEMODE_Truncate)) { | 168 if (!dst.Open(fileNameDst, FX_FILEMODE_Truncate)) { |
169 return FALSE; | 169 return false; |
170 } | 170 } |
171 FX_FILESIZE num = 0; | 171 FX_FILESIZE num = 0; |
172 uint8_t* pBuffer = FX_Alloc(uint8_t, 32768); | 172 uint8_t* pBuffer = FX_Alloc(uint8_t, 32768); |
173 while (num = src.Read(pBuffer, 32768)) { | 173 while (num = src.Read(pBuffer, 32768)) { |
174 if (dst.Write(pBuffer, num) != num) { | 174 if (dst.Write(pBuffer, num) != num) { |
175 break; | 175 break; |
176 } | 176 } |
177 } | 177 } |
178 FX_Free(pBuffer); | 178 FX_Free(pBuffer); |
179 return TRUE; | 179 return true; |
180 } | 180 } |
181 FX_BOOL FX_File_Copy(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC&
fileNameDst) | 181 bool FX_File_Copy(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fil
eNameDst) |
182 { | 182 { |
183 return FX_File_Copy(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); | 183 return FX_File_Copy(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); |
184 } | 184 } |
185 FX_BOOL FX_File_Move(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC&
fileNameDst) | 185 bool FX_File_Move(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fil
eNameDst) |
186 { | 186 { |
187 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); | 187 return rename(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); |
188 } | 188 } |
189 FX_BOOL FX_File_Move(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC&
fileNameDst) | 189 bool FX_File_Move(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fil
eNameDst) |
190 { | 190 { |
191 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); | 191 return FX_File_Move(FX_UTF8Encode(fileNameSrc), FX_UTF8Encode(fileNameDst)); |
192 } | 192 } |
193 #endif | 193 #endif |
OLD | NEW |