Skip to content

Commit

Permalink
Clean up porting.h a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Dec 15, 2023
1 parent e7be135 commit d4123a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/porting.cpp
Expand Up @@ -52,6 +52,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting_android.h"
#endif
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#include <CoreFoundation/CoreFoundation.h>
// For _NSGetEnviron()
// Related: https://gitlab.haskell.org/ghc/ghc/issues/2458
#include <crt_externs.h>
Expand Down
30 changes: 6 additions & 24 deletions src/porting.h
Expand Up @@ -38,23 +38,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define SWPRINTF_CHARSTRING L"%s"
#endif

//currently not needed
//template<typename T> struct alignment_trick { char c; T member; };
//#define ALIGNOF(type) offsetof (alignment_trick<type>, member)

#ifdef _WIN32
#include <windows.h>

#define sleep_ms(x) Sleep(x)
#define sleep_us(x) Sleep((x)/1000)
#else
#include <unistd.h>
#include <cstdint> //for uintptr_t

// Use standard Posix macro for Linux
#if (defined(linux) || defined(__linux)) && !defined(__linux__)
#define __linux__
#endif
#if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
Expand All @@ -64,18 +55,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif

#ifdef _MSC_VER
#define ALIGNOF(x) __alignof(x)
#define strtok_r(x, y, z) strtok_s(x, y, z)
#define strtof(x, y) (float)strtod(x, y)
#define strtoll(x, y, z) _strtoi64(x, y, z)
#define strtoull(x, y, z) _strtoui64(x, y, z)
#define strcasecmp(x, y) stricmp(x, y)
#define strncasecmp(x, y, n) strnicmp(x, y, n)
#else
#define ALIGNOF(x) __alignof__(x)
#endif

#ifdef __MINGW32__
// was broken in 2013, unclear if still needed
#define strtok_r(x, y, z) mystrtok_r(x, y, z)
#endif

Expand All @@ -97,18 +86,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define strlcpy(d, s, n) mystrlcpy(d, s, n)
#endif

#define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1))

#if defined(__APPLE__)
#include <mach-o/dyld.h>
#include <CoreFoundation/CoreFoundation.h>
#endif

#ifndef _WIN32 // Posix
#ifndef _WIN32 // POSIX
#include <sys/time.h>
#include <ctime>

#if defined(__MACH__) && defined(__APPLE__)
#if defined(__MACH__) && defined(__APPLE__)
#include <mach/clock.h>
#include <mach/mach.h>
#endif
Expand Down Expand Up @@ -178,7 +160,7 @@ void initializePaths();
std::string get_sysinfo();


// Monotonic counter getters.
// Monotonic timer

#ifdef _WIN32 // Windows

Expand All @@ -197,7 +179,7 @@ inline u64 getTimeMs() { return os_get_time(1000); }
inline u64 getTimeUs() { return os_get_time(1000*1000); }
inline u64 getTimeNs() { return os_get_time(1000*1000*1000); }

#else // Posix
#else // POSIX

inline void os_get_clock(struct timespec *ts)
{
Expand Down Expand Up @@ -314,7 +296,7 @@ inline const char *getPlatformName()
"Cygwin"
#elif defined(__unix__) || defined(__unix)
#if defined(_POSIX_VERSION)
"Posix"
"POSIX"
#else
"Unix"
#endif
Expand Down

0 comments on commit d4123a3

Please sign in to comment.