summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp113
1 files changed, 59 insertions, 54 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 2d0b81c6e..7213abe18 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -118,7 +118,7 @@ bool IsDirectory(const std::string& filename) {
118#endif 118#endif
119 119
120 if (result < 0) { 120 if (result < 0) {
121 NGLOG_DEBUG(Common_Filesystem, "stat failed on {}: {}", filename, GetLastErrorMsg()); 121 LOG_DEBUG(Common_Filesystem, "stat failed on {}: {}", filename, GetLastErrorMsg());
122 return false; 122 return false;
123 } 123 }
124 124
@@ -128,29 +128,29 @@ bool IsDirectory(const std::string& filename) {
128// Deletes a given filename, return true on success 128// Deletes a given filename, return true on success
129// Doesn't supports deleting a directory 129// Doesn't supports deleting a directory
130bool Delete(const std::string& filename) { 130bool Delete(const std::string& filename) {
131 NGLOG_TRACE(Common_Filesystem, "file {}", filename); 131 LOG_TRACE(Common_Filesystem, "file {}", filename);
132 132
133 // Return true because we care about the file no 133 // Return true because we care about the file no
134 // being there, not the actual delete. 134 // being there, not the actual delete.
135 if (!Exists(filename)) { 135 if (!Exists(filename)) {
136 NGLOG_DEBUG(Common_Filesystem, "{} does not exist", filename); 136 LOG_DEBUG(Common_Filesystem, "{} does not exist", filename);
137 return true; 137 return true;
138 } 138 }
139 139
140 // We can't delete a directory 140 // We can't delete a directory
141 if (IsDirectory(filename)) { 141 if (IsDirectory(filename)) {
142 NGLOG_ERROR(Common_Filesystem, "Failed: {} is a directory", filename); 142 LOG_ERROR(Common_Filesystem, "Failed: {} is a directory", filename);
143 return false; 143 return false;
144 } 144 }
145 145
146#ifdef _WIN32 146#ifdef _WIN32
147 if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) { 147 if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str())) {
148 NGLOG_ERROR(Common_Filesystem, "DeleteFile failed on {}: {}", filename, GetLastErrorMsg()); 148 LOG_ERROR(Common_Filesystem, "DeleteFile failed on {}: {}", filename, GetLastErrorMsg());
149 return false; 149 return false;
150 } 150 }
151#else 151#else
152 if (unlink(filename.c_str()) == -1) { 152 if (unlink(filename.c_str()) == -1) {
153 NGLOG_ERROR(Common_Filesystem, "unlink failed on {}: {}", filename, GetLastErrorMsg()); 153 LOG_ERROR(Common_Filesystem, "unlink failed on {}: {}", filename, GetLastErrorMsg());
154 return false; 154 return false;
155 } 155 }
156#endif 156#endif
@@ -160,16 +160,16 @@ bool Delete(const std::string& filename) {
160 160
161// Returns true if successful, or path already exists. 161// Returns true if successful, or path already exists.
162bool CreateDir(const std::string& path) { 162bool CreateDir(const std::string& path) {
163 NGLOG_TRACE(Common_Filesystem, "directory {}", path); 163 LOG_TRACE(Common_Filesystem, "directory {}", path);
164#ifdef _WIN32 164#ifdef _WIN32
165 if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr)) 165 if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr))
166 return true; 166 return true;
167 DWORD error = GetLastError(); 167 DWORD error = GetLastError();
168 if (error == ERROR_ALREADY_EXISTS) { 168 if (error == ERROR_ALREADY_EXISTS) {
169 NGLOG_DEBUG(Common_Filesystem, "CreateDirectory failed on {}: already exists", path); 169 LOG_DEBUG(Common_Filesystem, "CreateDirectory failed on {}: already exists", path);
170 return true; 170 return true;
171 } 171 }
172 NGLOG_ERROR(Common_Filesystem, "CreateDirectory failed on {}: {}", path, error); 172 LOG_ERROR(Common_Filesystem, "CreateDirectory failed on {}: {}", path, error);
173 return false; 173 return false;
174#else 174#else
175 if (mkdir(path.c_str(), 0755) == 0) 175 if (mkdir(path.c_str(), 0755) == 0)
@@ -178,11 +178,11 @@ bool CreateDir(const std::string& path) {
178 int err = errno; 178 int err = errno;
179 179
180 if (err == EEXIST) { 180 if (err == EEXIST) {
181 NGLOG_DEBUG(Common_Filesystem, "mkdir failed on {}: already exists", path); 181 LOG_DEBUG(Common_Filesystem, "mkdir failed on {}: already exists", path);
182 return true; 182 return true;
183 } 183 }
184 184
185 NGLOG_ERROR(Common_Filesystem, "mkdir failed on {}: {}", path, strerror(err)); 185 LOG_ERROR(Common_Filesystem, "mkdir failed on {}: {}", path, strerror(err));
186 return false; 186 return false;
187#endif 187#endif
188} 188}
@@ -190,10 +190,10 @@ bool CreateDir(const std::string& path) {
190// Creates the full path of fullPath returns true on success 190// Creates the full path of fullPath returns true on success
191bool CreateFullPath(const std::string& fullPath) { 191bool CreateFullPath(const std::string& fullPath) {
192 int panicCounter = 100; 192 int panicCounter = 100;
193 NGLOG_TRACE(Common_Filesystem, "path {}", fullPath); 193 LOG_TRACE(Common_Filesystem, "path {}", fullPath);
194 194
195 if (FileUtil::Exists(fullPath)) { 195 if (FileUtil::Exists(fullPath)) {
196 NGLOG_DEBUG(Common_Filesystem, "path exists {}", fullPath); 196 LOG_DEBUG(Common_Filesystem, "path exists {}", fullPath);
197 return true; 197 return true;
198 } 198 }
199 199
@@ -209,14 +209,14 @@ bool CreateFullPath(const std::string& fullPath) {
209 // Include the '/' so the first call is CreateDir("/") rather than CreateDir("") 209 // Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
210 std::string const subPath(fullPath.substr(0, position + 1)); 210 std::string const subPath(fullPath.substr(0, position + 1));
211 if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) { 211 if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) {
212 NGLOG_ERROR(Common, "CreateFullPath: directory creation failed"); 212 LOG_ERROR(Common, "CreateFullPath: directory creation failed");
213 return false; 213 return false;
214 } 214 }
215 215
216 // A safety check 216 // A safety check
217 panicCounter--; 217 panicCounter--;
218 if (panicCounter <= 0) { 218 if (panicCounter <= 0) {
219 NGLOG_ERROR(Common, "CreateFullPath: directory structure is too deep"); 219 LOG_ERROR(Common, "CreateFullPath: directory structure is too deep");
220 return false; 220 return false;
221 } 221 }
222 position++; 222 position++;
@@ -225,11 +225,11 @@ bool CreateFullPath(const std::string& fullPath) {
225 225
226// Deletes a directory filename, returns true on success 226// Deletes a directory filename, returns true on success
227bool DeleteDir(const std::string& filename) { 227bool DeleteDir(const std::string& filename) {
228 NGLOG_TRACE(Common_Filesystem, "directory {}", filename); 228 LOG_TRACE(Common_Filesystem, "directory {}", filename);
229 229
230 // check if a directory 230 // check if a directory
231 if (!FileUtil::IsDirectory(filename)) { 231 if (!FileUtil::IsDirectory(filename)) {
232 NGLOG_ERROR(Common_Filesystem, "Not a directory {}", filename); 232 LOG_ERROR(Common_Filesystem, "Not a directory {}", filename);
233 return false; 233 return false;
234 } 234 }
235 235
@@ -240,14 +240,14 @@ bool DeleteDir(const std::string& filename) {
240 if (rmdir(filename.c_str()) == 0) 240 if (rmdir(filename.c_str()) == 0)
241 return true; 241 return true;
242#endif 242#endif
243 NGLOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg()); 243 LOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg());
244 244
245 return false; 245 return false;
246} 246}
247 247
248// renames file srcFilename to destFilename, returns true on success 248// renames file srcFilename to destFilename, returns true on success
249bool Rename(const std::string& srcFilename, const std::string& destFilename) { 249bool Rename(const std::string& srcFilename, const std::string& destFilename) {
250 NGLOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename); 250 LOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename);
251#ifdef _WIN32 251#ifdef _WIN32
252 if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), 252 if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(),
253 Common::UTF8ToUTF16W(destFilename).c_str()) == 0) 253 Common::UTF8ToUTF16W(destFilename).c_str()) == 0)
@@ -256,21 +256,21 @@ bool Rename(const std::string& srcFilename, const std::string& destFilename) {
256 if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) 256 if (rename(srcFilename.c_str(), destFilename.c_str()) == 0)
257 return true; 257 return true;
258#endif 258#endif
259 NGLOG_ERROR(Common_Filesystem, "failed {} --> {}: {}", srcFilename, destFilename, 259 LOG_ERROR(Common_Filesystem, "failed {} --> {}: {}", srcFilename, destFilename,
260 GetLastErrorMsg()); 260 GetLastErrorMsg());
261 return false; 261 return false;
262} 262}
263 263
264// copies file srcFilename to destFilename, returns true on success 264// copies file srcFilename to destFilename, returns true on success
265bool Copy(const std::string& srcFilename, const std::string& destFilename) { 265bool Copy(const std::string& srcFilename, const std::string& destFilename) {
266 NGLOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename); 266 LOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename);
267#ifdef _WIN32 267#ifdef _WIN32
268 if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), 268 if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(),
269 Common::UTF8ToUTF16W(destFilename).c_str(), FALSE)) 269 Common::UTF8ToUTF16W(destFilename).c_str(), FALSE))
270 return true; 270 return true;
271 271
272 NGLOG_ERROR(Common_Filesystem, "failed {} --> {}: {}", srcFilename, destFilename, 272 LOG_ERROR(Common_Filesystem, "failed {} --> {}: {}", srcFilename, destFilename,
273 GetLastErrorMsg()); 273 GetLastErrorMsg());
274 return false; 274 return false;
275#else 275#else
276 276
@@ -282,8 +282,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) {
282 // Open input file 282 // Open input file
283 FILE* input = fopen(srcFilename.c_str(), "rb"); 283 FILE* input = fopen(srcFilename.c_str(), "rb");
284 if (!input) { 284 if (!input) {
285 NGLOG_ERROR(Common_Filesystem, "opening input failed {} --> {}: {}", srcFilename, 285 LOG_ERROR(Common_Filesystem, "opening input failed {} --> {}: {}", srcFilename,
286 destFilename, GetLastErrorMsg()); 286 destFilename, GetLastErrorMsg());
287 return false; 287 return false;
288 } 288 }
289 289
@@ -291,8 +291,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) {
291 FILE* output = fopen(destFilename.c_str(), "wb"); 291 FILE* output = fopen(destFilename.c_str(), "wb");
292 if (!output) { 292 if (!output) {
293 fclose(input); 293 fclose(input);
294 NGLOG_ERROR(Common_Filesystem, "opening output failed {} --> {}: {}", srcFilename, 294 LOG_ERROR(Common_Filesystem, "opening output failed {} --> {}: {}", srcFilename,
295 destFilename, GetLastErrorMsg()); 295 destFilename, GetLastErrorMsg());
296 return false; 296 return false;
297 } 297 }
298 298
@@ -302,8 +302,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) {
302 size_t rnum = fread(buffer, sizeof(char), BSIZE, input); 302 size_t rnum = fread(buffer, sizeof(char), BSIZE, input);
303 if (rnum != BSIZE) { 303 if (rnum != BSIZE) {
304 if (ferror(input) != 0) { 304 if (ferror(input) != 0) {
305 NGLOG_ERROR(Common_Filesystem, "failed reading from source, {} --> {}: {}", 305 LOG_ERROR(Common_Filesystem, "failed reading from source, {} --> {}: {}",
306 srcFilename, destFilename, GetLastErrorMsg()); 306 srcFilename, destFilename, GetLastErrorMsg());
307 goto bail; 307 goto bail;
308 } 308 }
309 } 309 }
@@ -311,8 +311,8 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) {
311 // write output 311 // write output
312 size_t wnum = fwrite(buffer, sizeof(char), rnum, output); 312 size_t wnum = fwrite(buffer, sizeof(char), rnum, output);
313 if (wnum != rnum) { 313 if (wnum != rnum) {
314 NGLOG_ERROR(Common_Filesystem, "failed writing to output, {} --> {}: {}", srcFilename, 314 LOG_ERROR(Common_Filesystem, "failed writing to output, {} --> {}: {}", srcFilename,
315 destFilename, GetLastErrorMsg()); 315 destFilename, GetLastErrorMsg());
316 goto bail; 316 goto bail;
317 } 317 }
318 } 318 }
@@ -332,12 +332,12 @@ bail:
332// Returns the size of filename (64bit) 332// Returns the size of filename (64bit)
333u64 GetSize(const std::string& filename) { 333u64 GetSize(const std::string& filename) {
334 if (!Exists(filename)) { 334 if (!Exists(filename)) {
335 NGLOG_ERROR(Common_Filesystem, "failed {}: No such file", filename); 335 LOG_ERROR(Common_Filesystem, "failed {}: No such file", filename);
336 return 0; 336 return 0;
337 } 337 }
338 338
339 if (IsDirectory(filename)) { 339 if (IsDirectory(filename)) {
340 NGLOG_ERROR(Common_Filesystem, "failed {}: is a directory", filename); 340 LOG_ERROR(Common_Filesystem, "failed {}: is a directory", filename);
341 return 0; 341 return 0;
342 } 342 }
343 343
@@ -348,11 +348,11 @@ u64 GetSize(const std::string& filename) {
348 if (stat(filename.c_str(), &buf) == 0) 348 if (stat(filename.c_str(), &buf) == 0)
349#endif 349#endif
350 { 350 {
351 NGLOG_TRACE(Common_Filesystem, "{}: {}", filename, buf.st_size); 351 LOG_TRACE(Common_Filesystem, "{}: {}", filename, buf.st_size);
352 return buf.st_size; 352 return buf.st_size;
353 } 353 }
354 354
355 NGLOG_ERROR(Common_Filesystem, "Stat failed {}: {}", filename, GetLastErrorMsg()); 355 LOG_ERROR(Common_Filesystem, "Stat failed {}: {}", filename, GetLastErrorMsg());
356 return 0; 356 return 0;
357} 357}
358 358
@@ -360,7 +360,7 @@ u64 GetSize(const std::string& filename) {
360u64 GetSize(const int fd) { 360u64 GetSize(const int fd) {
361 struct stat buf; 361 struct stat buf;
362 if (fstat(fd, &buf) != 0) { 362 if (fstat(fd, &buf) != 0) {
363 NGLOG_ERROR(Common_Filesystem, "GetSize: stat failed {}: {}", fd, GetLastErrorMsg()); 363 LOG_ERROR(Common_Filesystem, "GetSize: stat failed {}: {}", fd, GetLastErrorMsg());
364 return 0; 364 return 0;
365 } 365 }
366 return buf.st_size; 366 return buf.st_size;
@@ -371,14 +371,12 @@ u64 GetSize(FILE* f) {
371 // can't use off_t here because it can be 32-bit 371 // can't use off_t here because it can be 32-bit
372 u64 pos = ftello(f); 372 u64 pos = ftello(f);
373 if (fseeko(f, 0, SEEK_END) != 0) { 373 if (fseeko(f, 0, SEEK_END) != 0) {
374 NGLOG_ERROR(Common_Filesystem, "GetSize: seek failed {}: {}", fmt::ptr(f), 374 LOG_ERROR(Common_Filesystem, "GetSize: seek failed {}: {}", fmt::ptr(f), GetLastErrorMsg());
375 GetLastErrorMsg());
376 return 0; 375 return 0;
377 } 376 }
378 u64 size = ftello(f); 377 u64 size = ftello(f);
379 if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) { 378 if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) {
380 NGLOG_ERROR(Common_Filesystem, "GetSize: seek failed {}: {}", fmt::ptr(f), 379 LOG_ERROR(Common_Filesystem, "GetSize: seek failed {}: {}", fmt::ptr(f), GetLastErrorMsg());
381 GetLastErrorMsg());
382 return 0; 380 return 0;
383 } 381 }
384 return size; 382 return size;
@@ -386,10 +384,10 @@ u64 GetSize(FILE* f) {
386 384
387// creates an empty file filename, returns true on success 385// creates an empty file filename, returns true on success
388bool CreateEmptyFile(const std::string& filename) { 386bool CreateEmptyFile(const std::string& filename) {
389 NGLOG_TRACE(Common_Filesystem, "{}", filename); 387 LOG_TRACE(Common_Filesystem, "{}", filename);
390 388
391 if (!FileUtil::IOFile(filename, "wb")) { 389 if (!FileUtil::IOFile(filename, "wb")) {
392 NGLOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg()); 390 LOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg());
393 return false; 391 return false;
394 } 392 }
395 393
@@ -398,7 +396,7 @@ bool CreateEmptyFile(const std::string& filename) {
398 396
399bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory, 397bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory,
400 DirectoryEntryCallable callback) { 398 DirectoryEntryCallable callback) {
401 NGLOG_TRACE(Common_Filesystem, "directory {}", directory); 399 LOG_TRACE(Common_Filesystem, "directory {}", directory);
402 400
403 // How many files + directories we found 401 // How many files + directories we found
404 unsigned found_entries = 0; 402 unsigned found_entries = 0;
@@ -556,7 +554,7 @@ std::string GetCurrentDir() {
556 char* dir; 554 char* dir;
557 if (!(dir = getcwd(nullptr, 0))) { 555 if (!(dir = getcwd(nullptr, 0))) {
558#endif 556#endif
559 NGLOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg()); 557 LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg());
560 return nullptr; 558 return nullptr;
561 } 559 }
562#ifdef _WIN32 560#ifdef _WIN32
@@ -676,11 +674,11 @@ std::string GetSysDirectory() {
676#endif 674#endif
677 sysDir += DIR_SEP; 675 sysDir += DIR_SEP;
678 676
679 NGLOG_DEBUG(Common_Filesystem, "Setting to {}:", sysDir); 677 LOG_DEBUG(Common_Filesystem, "Setting to {}:", sysDir);
680 return sysDir; 678 return sysDir;
681} 679}
682 680
683// Returns a string with a Citra data dir or file in the user's home 681// Returns a string with a yuzu data dir or file in the user's home
684// directory. To be used in "multi-user" mode (that is, installed). 682// directory. To be used in "multi-user" mode (that is, installed).
685const std::string& GetUserPath(const unsigned int DirIDX, const std::string& newPath) { 683const std::string& GetUserPath(const unsigned int DirIDX, const std::string& newPath) {
686 static std::string paths[NUM_PATH_INDICES]; 684 static std::string paths[NUM_PATH_INDICES];
@@ -692,7 +690,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new
692 if (!FileUtil::IsDirectory(paths[D_USER_IDX])) { 690 if (!FileUtil::IsDirectory(paths[D_USER_IDX])) {
693 paths[D_USER_IDX] = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP; 691 paths[D_USER_IDX] = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
694 } else { 692 } else {
695 NGLOG_INFO(Common_Filesystem, "Using the local user directory"); 693 LOG_INFO(Common_Filesystem, "Using the local user directory");
696 } 694 }
697 695
698 paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; 696 paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
@@ -715,11 +713,13 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new
715 paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; 713 paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
716 paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; 714 paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP;
717 paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP; 715 paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP;
716 // TODO: Put the logs in a better location for each OS
717 paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOG_DIR DIR_SEP;
718 } 718 }
719 719
720 if (!newPath.empty()) { 720 if (!newPath.empty()) {
721 if (!FileUtil::IsDirectory(newPath)) { 721 if (!FileUtil::IsDirectory(newPath)) {
722 NGLOG_ERROR(Common_Filesystem, "Invalid path specified {}", newPath); 722 LOG_ERROR(Common_Filesystem, "Invalid path specified {}", newPath);
723 return paths[DirIDX]; 723 return paths[DirIDX];
724 } else { 724 } else {
725 paths[DirIDX] = newPath; 725 paths[DirIDX] = newPath;
@@ -801,8 +801,8 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam
801 801
802IOFile::IOFile() {} 802IOFile::IOFile() {}
803 803
804IOFile::IOFile(const std::string& filename, const char openmode[]) { 804IOFile::IOFile(const std::string& filename, const char openmode[], int flags) {
805 Open(filename, openmode); 805 Open(filename, openmode, flags);
806} 806}
807 807
808IOFile::~IOFile() { 808IOFile::~IOFile() {
@@ -823,11 +823,16 @@ void IOFile::Swap(IOFile& other) noexcept {
823 std::swap(m_good, other.m_good); 823 std::swap(m_good, other.m_good);
824} 824}
825 825
826bool IOFile::Open(const std::string& filename, const char openmode[]) { 826bool IOFile::Open(const std::string& filename, const char openmode[], int flags) {
827 Close(); 827 Close();
828#ifdef _WIN32 828#ifdef _WIN32
829 _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), 829 if (flags != 0) {
830 Common::UTF8ToUTF16W(openmode).c_str()); 830 m_file = _wfsopen(Common::UTF8ToUTF16W(filename).c_str(),
831 Common::UTF8ToUTF16W(openmode).c_str(), flags);
832 } else {
833 _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(),
834 Common::UTF8ToUTF16W(openmode).c_str());
835 }
831#else 836#else
832 m_file = fopen(filename.c_str(), openmode); 837 m_file = fopen(filename.c_str(), openmode);
833#endif 838#endif