spdlog: backport support for more Unices

53b2308011
8d57823e51
This commit is contained in:
Jan Beich 2020-01-01 10:51:17 +00:00
parent 6bd46985c4
commit f573e35c46
1 changed files with 23 additions and 7 deletions

View File

@ -39,8 +39,20 @@
#include <unistd.h>
#include <chrono>
#elif __FreeBSD__
#include <sys/thr.h> //Use thr_self() syscall under FreeBSD to get thread id
#elif defined(_AIX)
#include <pthread.h> // for pthread_getthreadid_np
#elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np
#elif defined(__NetBSD__)
#include <lwp.h> // for _lwp_self
#elif defined(__OpenBSD__)
#include <unistd.h> // for getthrid
#elif defined(__sun)
#include <thread.h> // for thr_self
#else
#include <thread>
@ -213,7 +225,7 @@ inline size_t filesize(FILE *f)
#else // unix
int fd = fileno(f);
//64 bits(but not in osx, where fstat64 is deprecated)
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
#if (defined(__linux__) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64))
struct stat64 st;
if (fstat64(fd, &st) == 0)
return static_cast<size_t>(st.st_size);
@ -302,10 +314,14 @@ inline size_t thread_id()
# define SYS_gettid __NR_gettid
# endif
return static_cast<size_t>(syscall(SYS_gettid));
#elif __FreeBSD__
long tid;
thr_self(&tid);
return static_cast<size_t>(tid);
#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD__)
return static_cast<size_t>(pthread_getthreadid_np());
#elif defined(__NetBSD__)
return static_cast<size_t>(_lwp_self());
#elif defined(__OpenBSD__)
return static_cast<size_t>(getthrid());
#elif defined(__sun)
return static_cast<size_t>(thr_self());
#else //Default to standard C++11 (OSX and other Unix)
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
#endif