Merge pull request #4018 from bentley/openbsd-ifdefs

Openbsd ifdefs
This commit is contained in:
Matthew Parlane 2016-07-18 16:12:06 +12:00 committed by GitHub
commit a51c992e61
6 changed files with 17 additions and 11 deletions

View File

@ -20,7 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#if defined __APPLE__ || defined __FreeBSD__ #if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__
#include <sys/sysctl.h> #include <sys/sysctl.h>
#else #else
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
@ -253,7 +253,7 @@ size_t MemPhysical()
memInfo.dwLength = sizeof(MEMORYSTATUSEX); memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo); GlobalMemoryStatusEx(&memInfo);
return memInfo.ullTotalPhys; return memInfo.ullTotalPhys;
#elif defined __APPLE__ || defined __FreeBSD__ #elif defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__
int mib[2]; int mib[2];
size_t physical_memory; size_t physical_memory;
mib[0] = CTL_HW; mib[0] = CTL_HW;
@ -261,6 +261,8 @@ size_t MemPhysical()
mib[1] = HW_MEMSIZE; mib[1] = HW_MEMSIZE;
#elif defined __FreeBSD__ #elif defined __FreeBSD__
mib[1] = HW_REALMEM; mib[1] = HW_REALMEM;
#elif defined __OpenBSD__
mib[1] = HW_PHYSMEM;
#endif #endif
size_t length = sizeof(size_t); size_t length = sizeof(size_t);
sysctl(mib, 2, &physical_memory, &length, NULL, 0); sysctl(mib, 2, &physical_memory, &length, NULL, 0);

View File

@ -28,7 +28,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
#if !defined(_WIN32) && !defined(ANDROID) #if !defined(_WIN32) && !defined(ANDROID) && !defined(__OpenBSD__)
static locale_t GetCLocale() static locale_t GetCLocale()
{ {
static locale_t c_locale = newlocale(LC_ALL_MASK, "C", nullptr); static locale_t c_locale = newlocale(LC_ALL_MASK, "C", nullptr);
@ -121,11 +121,11 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
c_locale = _create_locale(LC_ALL, "C"); c_locale = _create_locale(LC_ALL, "C");
writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args); writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
#else #else
#if !defined(ANDROID) #if !defined(ANDROID) && !defined(__OpenBSD__)
locale_t previousLocale = uselocale(GetCLocale()); locale_t previousLocale = uselocale(GetCLocale());
#endif #endif
writtenCount = vsnprintf(out, outsize, format, args); writtenCount = vsnprintf(out, outsize, format, args);
#if !defined(ANDROID) #if !defined(ANDROID) && !defined(__OpenBSD__)
uselocale(previousLocale); uselocale(previousLocale);
#endif #endif
#endif #endif
@ -162,12 +162,12 @@ std::string StringFromFormatV(const char* format, va_list args)
std::string temp = buf; std::string temp = buf;
delete[] buf; delete[] buf;
#else #else
#if !defined(ANDROID) #if !defined(ANDROID) && !defined(__OpenBSD__)
locale_t previousLocale = uselocale(GetCLocale()); locale_t previousLocale = uselocale(GetCLocale());
#endif #endif
if (vasprintf(&buf, format, args) < 0) if (vasprintf(&buf, format, args) < 0)
ERROR_LOG(COMMON, "Unable to allocate memory for string"); ERROR_LOG(COMMON, "Unable to allocate memory for string");
#if !defined(ANDROID) #if !defined(ANDROID) && !defined(__OpenBSD__)
uselocale(previousLocale); uselocale(previousLocale);
#endif #endif

View File

@ -12,7 +12,7 @@
#ifdef __APPLE__ #ifdef __APPLE__
#include <mach/mach.h> #include <mach/mach.h>
#elif defined BSD4_4 || defined __FreeBSD__ #elif defined BSD4_4 || defined __FreeBSD__ || defined __OpenBSD__
#include <pthread_np.h> #include <pthread_np.h>
#endif #endif
@ -132,7 +132,7 @@ void SetCurrentThreadName(const char* szThreadName)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
pthread_setname_np(szThreadName); pthread_setname_np(szThreadName);
#elif defined __FreeBSD__ #elif defined __FreeBSD__ || defined __OpenBSD__
pthread_set_name_np(pthread_self(), szThreadName); pthread_set_name_np(pthread_self(), szThreadName);
#else #else
// linux doesn't allow to set more than 16 bytes, including \0. // linux doesn't allow to set more than 16 bytes, including \0.

View File

@ -327,11 +327,12 @@ public:
OVERLAPPED mWriteOverlapped; OVERLAPPED mWriteOverlapped;
std::vector<u8> mWriteBuffer; std::vector<u8> mWriteBuffer;
bool mWritePending; bool mWritePending;
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
int fd; int fd;
#endif #endif
#if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) #if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(__OpenBSD__)
std::thread readThread; std::thread readThread;
Common::Flag readEnabled; Common::Flag readEnabled;
Common::Flag readThreadShutdown; Common::Flag readThreadShutdown;

View File

@ -32,6 +32,8 @@ const u32 m_os = OS_ALL | OS_OSX;
const u32 m_os = OS_ALL | OS_LINUX; const u32 m_os = OS_ALL | OS_LINUX;
#elif __FreeBSD__ #elif __FreeBSD__
const u32 m_os = OS_ALL | OS_FREEBSD; const u32 m_os = OS_ALL | OS_FREEBSD;
#elif __OpenBSD__
const u32 m_os = OS_ALL | OS_OPENBSD;
#endif #endif
static Vendor m_vendor = VENDOR_UNKNOWN; static Vendor m_vendor = VENDOR_UNKNOWN;

View File

@ -17,6 +17,7 @@ enum OS
OS_OSX = (1 << 3), OS_OSX = (1 << 3),
OS_ANDROID = (1 << 4), OS_ANDROID = (1 << 4),
OS_FREEBSD = (1 << 5), OS_FREEBSD = (1 << 5),
OS_OPENBSD = (1 << 6),
}; };
// Enum of known vendors // Enum of known vendors
// Tegra and Nvidia are separated out due to such substantial differences // Tegra and Nvidia are separated out due to such substantial differences