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.cpp54
1 files changed, 32 insertions, 22 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 4ef4918d7..7cdd1484f 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -2,42 +2,52 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5 5#include "common/assert.h"
6#include "common/common.h" 6#include "common/common_funcs.h"
7#include "common/common_paths.h"
7#include "common/file_util.h" 8#include "common/file_util.h"
9#include "common/logging/log.h"
8 10
9#ifdef _WIN32 11#ifdef _WIN32
10#include <windows.h> 12 #include <windows.h>
11#include <shlobj.h> // for SHGetFolderPath 13 #include <shlobj.h> // for SHGetFolderPath
12#include <shellapi.h> 14 #include <shellapi.h>
13#include <commdlg.h> // for GetSaveFileName 15 #include <commdlg.h> // for GetSaveFileName
14#include <io.h> 16 #include <io.h>
15#include <direct.h> // getcwd 17 #include <direct.h> // getcwd
16#include <tchar.h> 18 #include <tchar.h>
19
20 // 64 bit offsets for windows
21 #define fseeko _fseeki64
22 #define ftello _ftelli64
23 #define atoll _atoi64
24 #define stat64 _stat64
25 #define fstat64 _fstat64
26 #define fileno _fileno
17#else 27#else
18#include <sys/param.h> 28 #include <sys/param.h>
19#include <sys/types.h> 29 #include <sys/types.h>
20#include <dirent.h> 30 #include <dirent.h>
21#include <pwd.h> 31 #include <pwd.h>
22#include <unistd.h> 32 #include <unistd.h>
23#endif 33#endif
24 34
25#if defined(__APPLE__) 35#if defined(__APPLE__)
26#include <CoreFoundation/CFString.h> 36 #include <CoreFoundation/CFString.h>
27#include <CoreFoundation/CFURL.h> 37 #include <CoreFoundation/CFURL.h>
28#include <CoreFoundation/CFBundle.h> 38 #include <CoreFoundation/CFBundle.h>
29#endif 39#endif
30 40
31#include <algorithm> 41#include <algorithm>
32#include <sys/stat.h> 42#include <sys/stat.h>
33 43
34#ifndef S_ISDIR 44#ifndef S_ISDIR
35#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) 45 #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
36#endif 46#endif
37 47
38#ifdef BSD4_4 48#ifdef BSD4_4
39#define stat64 stat 49 #define stat64 stat
40#define fstat64 fstat 50 #define fstat64 fstat
41#endif 51#endif
42 52
43// This namespace has various generic functions related to files and paths. 53// This namespace has various generic functions related to files and paths.
@@ -589,7 +599,7 @@ std::string GetCurrentDir()
589{ 599{
590 char *dir; 600 char *dir;
591 // Get the current working directory (getcwd uses malloc) 601 // Get the current working directory (getcwd uses malloc)
592 if (!(dir = __getcwd(nullptr, 0))) { 602 if (!(dir = getcwd(nullptr, 0))) {
593 603
594 LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s", 604 LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s",
595 GetLastErrorMsg()); 605 GetLastErrorMsg());
@@ -603,7 +613,7 @@ std::string GetCurrentDir()
603// Sets the current directory to the given directory 613// Sets the current directory to the given directory
604bool SetCurrentDir(const std::string &directory) 614bool SetCurrentDir(const std::string &directory)
605{ 615{
606 return __chdir(directory.c_str()) == 0; 616 return chdir(directory.c_str()) == 0;
607} 617}
608 618
609#if defined(__APPLE__) 619#if defined(__APPLE__)