From 96a291d11f884b18356ba8ef4b12b82d658d8d04 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 1 Aug 2014 19:17:57 -0700 Subject: Add support for Mac OS X --- src/compat.h | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/compat.h') diff --git a/src/compat.h b/src/compat.h index af7264d..c73a340 100644 --- a/src/compat.h +++ b/src/compat.h @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -80,12 +81,20 @@ struct ethhdr { #endif +/** The type of the third parameter of getgrouplist */ +#ifdef __APPLE__ +#define GROUPLIST_TYPE int +#else +#define GROUPLIST_TYPE gid_t +#endif + + #ifndef HAVE_GET_CURRENT_DIR_NAME /** Replacement function for *BSD systems not supporting get_current_dir_name() */ static inline char *get_current_dir_name(void) { -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__) return getcwd(NULL, 0); @@ -98,3 +107,28 @@ static inline char *get_current_dir_name(void) { } #endif + + +#ifdef __APPLE__ + +#include + +#define CLOCK_MONOTONIC 0 +#define clockid_t int + +static inline int clock_gettime(clockid_t clk_id __attribute__((unused)), struct timespec *tp) { + static mach_timebase_info_data_t timebase_info = {}; + + if (!timebase_info.denom) + mach_timebase_info(&timebase_info); + + uint64_t time = (((long double)mach_absolute_time())*timebase_info.numer) / timebase_info.denom; + + tp->tv_sec = time / 1000000000; + tp->tv_nsec = time % 1000000000; + + return 0; +} + + +#endif -- cgit v1.2.3