summaryrefslogtreecommitdiffstats
path: root/src/compat.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 04:17:57 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 06:08:18 +0200
commit96a291d11f884b18356ba8ef4b12b82d658d8d04 (patch)
tree8ad328375c4b1754e69cd38ee4e2e13d60c28525 /src/compat.h
parente63fe3b8d058bed15d65728f8e9a7e4093040028 (diff)
downloadfastd-96a291d11f884b18356ba8ef4b12b82d658d8d04.tar
fastd-96a291d11f884b18356ba8ef4b12b82d658d8d04.zip
Add support for Mac OS X
Diffstat (limited to 'src/compat.h')
-rw-r--r--src/compat.h36
1 files changed, 35 insertions, 1 deletions
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 <fastd_config.h>
#include <stdint.h>
+#include <time.h>
#include <unistd.h>
#include <sys/types.h>
@@ -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 <mach/mach_time.h>
+
+#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