summaryrefslogtreecommitdiff
path: root/src/porting.h
diff options
context:
space:
mode:
authorMartin Doege <mdoege@compuserve.com>2014-06-26 20:30:22 +0200
committersapier <Sapier at GMX dot net>2014-06-29 17:27:33 +0200
commitc410e9182d322a8c095ef94fbadf4d8f541e6b98 (patch)
treeb4626b67e9f6f10b43395013c7a275037aa463a3 /src/porting.h
parentee7af21e411d5d43ba67f4b67603f72e62b0570d (diff)
downloadminetest-c410e9182d322a8c095ef94fbadf4d8f541e6b98.tar.gz
minetest-c410e9182d322a8c095ef94fbadf4d8f541e6b98.tar.bz2
minetest-c410e9182d322a8c095ef94fbadf4d8f541e6b98.zip
OS X compatibility fixes
Diffstat (limited to 'src/porting.h')
-rw-r--r--src/porting.h26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/porting.h b/src/porting.h
index 383d4377a..b5a5d00f2 100644
--- a/src/porting.h
+++ b/src/porting.h
@@ -123,6 +123,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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
+
namespace porting
{
@@ -220,9 +225,13 @@ void initIrrlicht(irr::IrrlichtDevice * );
}
#else // Posix
- #include <sys/time.h>
- #include <time.h>
-
+#include <sys/time.h>
+#include <time.h>
+#ifdef __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
+
inline u32 getTimeS()
{
struct timeval tv;
@@ -247,7 +256,18 @@ void initIrrlicht(irr::IrrlichtDevice * );
inline u32 getTimeNs()
{
struct timespec ts;
+ // from http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x
+#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+ clock_serv_t cclock;
+ mach_timespec_t mts;
+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+ clock_get_time(cclock, &mts);
+ mach_port_deallocate(mach_task_self(), cclock);
+ ts.tv_sec = mts.tv_sec;
+ ts.tv_nsec = mts.tv_nsec;
+#else
clock_gettime(CLOCK_REALTIME, &ts);
+#endif
return ts.tv_sec * 1000000000 + ts.tv_nsec;
}