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.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 14cbcac6b..407ed047a 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -23,8 +23,8 @@
23#define fseeko _fseeki64 23#define fseeko _fseeki64
24#define ftello _ftelli64 24#define ftello _ftelli64
25#define atoll _atoi64 25#define atoll _atoi64
26#define stat64 _stat64 26#define stat _stat64
27#define fstat64 _fstat64 27#define fstat _fstat64
28#define fileno _fileno 28#define fileno _fileno
29#else 29#else
30#ifdef __APPLE__ 30#ifdef __APPLE__
@@ -52,11 +52,6 @@
52#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) 52#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
53#endif 53#endif
54 54
55#ifdef BSD4_4
56#define stat64 stat
57#define fstat64 fstat
58#endif
59
60// This namespace has various generic functions related to files and paths. 55// This namespace has various generic functions related to files and paths.
61// The code still needs a ton of cleanup. 56// The code still needs a ton of cleanup.
62// REMEMBER: strdup considered harmful! 57// REMEMBER: strdup considered harmful!
@@ -76,7 +71,7 @@ static void StripTailDirSlashes(std::string& fname) {
76 71
77// Returns true if file filename exists 72// Returns true if file filename exists
78bool Exists(const std::string& filename) { 73bool Exists(const std::string& filename) {
79 struct stat64 file_info; 74 struct stat file_info;
80 75
81 std::string copy(filename); 76 std::string copy(filename);
82 StripTailDirSlashes(copy); 77 StripTailDirSlashes(copy);
@@ -88,7 +83,7 @@ bool Exists(const std::string& filename) {
88 83
89 int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); 84 int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
90#else 85#else
91 int result = stat64(copy.c_str(), &file_info); 86 int result = stat(copy.c_str(), &file_info);
92#endif 87#endif
93 88
94 return (result == 0); 89 return (result == 0);
@@ -96,7 +91,7 @@ bool Exists(const std::string& filename) {
96 91
97// Returns true if filename is a directory 92// Returns true if filename is a directory
98bool IsDirectory(const std::string& filename) { 93bool IsDirectory(const std::string& filename) {
99 struct stat64 file_info; 94 struct stat file_info;
100 95
101 std::string copy(filename); 96 std::string copy(filename);
102 StripTailDirSlashes(copy); 97 StripTailDirSlashes(copy);
@@ -108,7 +103,7 @@ bool IsDirectory(const std::string& filename) {
108 103
109 int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info); 104 int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
110#else 105#else
111 int result = stat64(copy.c_str(), &file_info); 106 int result = stat(copy.c_str(), &file_info);
112#endif 107#endif
113 108
114 if (result < 0) { 109 if (result < 0) {
@@ -339,11 +334,11 @@ u64 GetSize(const std::string& filename) {
339 return 0; 334 return 0;
340 } 335 }
341 336
342 struct stat64 buf; 337 struct stat buf;
343#ifdef _WIN32 338#ifdef _WIN32
344 if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0) 339 if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0)
345#else 340#else
346 if (stat64(filename.c_str(), &buf) == 0) 341 if (stat(filename.c_str(), &buf) == 0)
347#endif 342#endif
348 { 343 {
349 LOG_TRACE(Common_Filesystem, "%s: %lld", filename.c_str(), (long long)buf.st_size); 344 LOG_TRACE(Common_Filesystem, "%s: %lld", filename.c_str(), (long long)buf.st_size);
@@ -356,8 +351,8 @@ u64 GetSize(const std::string& filename) {
356 351
357// Overloaded GetSize, accepts file descriptor 352// Overloaded GetSize, accepts file descriptor
358u64 GetSize(const int fd) { 353u64 GetSize(const int fd) {
359 struct stat64 buf; 354 struct stat buf;
360 if (fstat64(fd, &buf) != 0) { 355 if (fstat(fd, &buf) != 0) {
361 LOG_ERROR(Common_Filesystem, "GetSize: stat failed %i: %s", fd, GetLastErrorMsg()); 356 LOG_ERROR(Common_Filesystem, "GetSize: stat failed %i: %s", fd, GetLastErrorMsg());
362 return 0; 357 return 0;
363 } 358 }