diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/file_util.cpp | 25 | ||||
| -rw-r--r-- | src/common/swap.h | 7 | ||||
| -rw-r--r-- | src/common/thread.cpp | 12 | ||||
| -rw-r--r-- | src/common/x64/cpu_detect.cpp | 8 |
4 files changed, 29 insertions, 23 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 |
| 78 | bool Exists(const std::string& filename) { | 73 | bool 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 |
| 98 | bool IsDirectory(const std::string& filename) { | 93 | bool 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 |
| 358 | u64 GetSize(const int fd) { | 353 | u64 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 | } |
diff --git a/src/common/swap.h b/src/common/swap.h index e241c9f73..d94cbe6b2 100644 --- a/src/common/swap.h +++ b/src/common/swap.h | |||
| @@ -21,7 +21,8 @@ | |||
| 21 | #include <cstdlib> | 21 | #include <cstdlib> |
| 22 | #elif defined(__linux__) | 22 | #elif defined(__linux__) |
| 23 | #include <byteswap.h> | 23 | #include <byteswap.h> |
| 24 | #elif defined(__FreeBSD__) | 24 | #elif defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ |
| 25 | defined(__NetBSD__) || defined(__OpenBSD__) | ||
| 25 | #include <sys/endian.h> | 26 | #include <sys/endian.h> |
| 26 | #endif | 27 | #endif |
| 27 | #include <cstring> | 28 | #include <cstring> |
| @@ -101,7 +102,9 @@ inline __attribute__((always_inline)) u32 swap32(u32 _data) { | |||
| 101 | inline __attribute__((always_inline)) u64 swap64(u64 _data) { | 102 | inline __attribute__((always_inline)) u64 swap64(u64 _data) { |
| 102 | return __builtin_bswap64(_data); | 103 | return __builtin_bswap64(_data); |
| 103 | } | 104 | } |
| 104 | #elif __FreeBSD__ | 105 | #elif defined(__Bitrig__) || defined(__OpenBSD__) |
| 106 | // swap16, swap32, swap64 are left as is | ||
| 107 | #elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) | ||
| 105 | inline u16 swap16(u16 _data) { | 108 | inline u16 swap16(u16 _data) { |
| 106 | return bswap16(_data); | 109 | return bswap16(_data); |
| 107 | } | 110 | } |
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 6e7b39b9a..9bb2f4e1d 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | #elif defined(_WIN32) | 8 | #elif defined(_WIN32) |
| 9 | #include <Windows.h> | 9 | #include <Windows.h> |
| 10 | #else | 10 | #else |
| 11 | #if defined(BSD4_4) || defined(__OpenBSD__) | 11 | #if defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
| 12 | #include <pthread_np.h> | 12 | #include <pthread_np.h> |
| 13 | #else | 13 | #else |
| 14 | #include <pthread.h> | 14 | #include <pthread.h> |
| @@ -19,6 +19,10 @@ | |||
| 19 | #include <unistd.h> | 19 | #include <unistd.h> |
| 20 | #endif | 20 | #endif |
| 21 | 21 | ||
| 22 | #ifdef __FreeBSD__ | ||
| 23 | #define cpu_set_t cpuset_t | ||
| 24 | #endif | ||
| 25 | |||
| 22 | namespace Common { | 26 | namespace Common { |
| 23 | 27 | ||
| 24 | int CurrentThreadId() { | 28 | int CurrentThreadId() { |
| @@ -86,7 +90,7 @@ void SetCurrentThreadName(const char* szThreadName) { | |||
| 86 | void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask) { | 90 | void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask) { |
| 87 | #ifdef __APPLE__ | 91 | #ifdef __APPLE__ |
| 88 | thread_policy_set(pthread_mach_thread_np(thread), THREAD_AFFINITY_POLICY, (integer_t*)&mask, 1); | 92 | thread_policy_set(pthread_mach_thread_np(thread), THREAD_AFFINITY_POLICY, (integer_t*)&mask, 1); |
| 89 | #elif (defined __linux__ || defined BSD4_4) && !(defined ANDROID) | 93 | #elif (defined __linux__ || defined __FreeBSD__) && !(defined ANDROID) |
| 90 | cpu_set_t cpu_set; | 94 | cpu_set_t cpu_set; |
| 91 | CPU_ZERO(&cpu_set); | 95 | CPU_ZERO(&cpu_set); |
| 92 | 96 | ||
| @@ -117,8 +121,10 @@ void SwitchCurrentThread() { | |||
| 117 | void SetCurrentThreadName(const char* szThreadName) { | 121 | void SetCurrentThreadName(const char* szThreadName) { |
| 118 | #ifdef __APPLE__ | 122 | #ifdef __APPLE__ |
| 119 | pthread_setname_np(szThreadName); | 123 | pthread_setname_np(szThreadName); |
| 120 | #elif defined(__OpenBSD__) | 124 | #elif defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
| 121 | pthread_set_name_np(pthread_self(), szThreadName); | 125 | pthread_set_name_np(pthread_self(), szThreadName); |
| 126 | #elif defined(__NetBSD__) | ||
| 127 | pthread_setname_np(pthread_self(), "%s", (void*)szThreadName); | ||
| 122 | #else | 128 | #else |
| 123 | pthread_setname_np(pthread_self(), szThreadName); | 129 | pthread_setname_np(pthread_self(), szThreadName); |
| 124 | #endif | 130 | #endif |
diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp index 6ddf9b70c..370ae2c80 100644 --- a/src/common/x64/cpu_detect.cpp +++ b/src/common/x64/cpu_detect.cpp | |||
| @@ -12,13 +12,15 @@ namespace Common { | |||
| 12 | 12 | ||
| 13 | #ifndef _MSC_VER | 13 | #ifndef _MSC_VER |
| 14 | 14 | ||
| 15 | #ifdef __FreeBSD__ | 15 | #if defined(__DragonFly__) || defined(__FreeBSD__) |
| 16 | #include <machine/cpufunc.h> | 16 | // clang-format off |
| 17 | #include <sys/types.h> | 17 | #include <sys/types.h> |
| 18 | #include <machine/cpufunc.h> | ||
| 19 | // clang-format on | ||
| 18 | #endif | 20 | #endif |
| 19 | 21 | ||
| 20 | static inline void __cpuidex(int info[4], int function_id, int subfunction_id) { | 22 | static inline void __cpuidex(int info[4], int function_id, int subfunction_id) { |
| 21 | #ifdef __FreeBSD__ | 23 | #if defined(__DragonFly__) || defined(__FreeBSD__) |
| 22 | // Despite the name, this is just do_cpuid() with ECX as second input. | 24 | // Despite the name, this is just do_cpuid() with ECX as second input. |
| 23 | cpuid_count((u_int)function_id, (u_int)subfunction_id, (u_int*)info); | 25 | cpuid_count((u_int)function_id, (u_int)subfunction_id, (u_int*)info); |
| 24 | #else | 26 | #else |