diff options
author | Alan T. DeKok <aland@freeradius.org> | 2015-09-22 10:56:51 -0400 |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2015-09-25 19:30:09 +0300 |
commit | b0c70f37b783998e5a4e4241f3fc55839514fa65 (patch) | |
tree | 0de002bd232b9f0623898ae8999a8bec5f635fa4 | |
parent | 10cac5b1a2549a3731e870c574bdd64df7d92877 (diff) | |
download | hostap-b0c70f37b783998e5a4e4241f3fc55839514fa65.tar.gz |
Portability fixes for OS X
Fix os_get_reltime() and os_fdatasync() for OS X.
Signed-off-by: Alan DeKok <aland@freeradius.org>
-rw-r--r-- | src/utils/os_unix.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c index 4754dd7a1..ffa2e788b 100644 --- a/src/utils/os_unix.c +++ b/src/utils/os_unix.c @@ -17,6 +17,12 @@ #include <private/android_filesystem_config.h> #endif /* ANDROID */ +#ifdef __MACH__ +#include <CoreServices/CoreServices.h> +#include <mach/mach.h> +#include <mach/mach_time.h> +#endif /* __MACH__ */ + #include "os.h" #include "common.h" @@ -63,6 +69,7 @@ int os_get_time(struct os_time *t) int os_get_reltime(struct os_reltime *t) { +#ifndef __MACH__ #if defined(CLOCK_BOOTTIME) static clockid_t clock_id = CLOCK_BOOTTIME; #elif defined(CLOCK_MONOTONIC) @@ -95,6 +102,23 @@ int os_get_reltime(struct os_reltime *t) return -1; } } +#else /* __MACH__ */ + uint64_t abstime, nano; + static mach_timebase_info_data_t info = { 0, 0 }; + + if (!info.denom) { + if (mach_timebase_info(&info) != KERN_SUCCESS) + return -1; + } + + abstime = mach_absolute_time(); + nano = (abstime * info.numer) / info.denom; + + t->sec = nano / NSEC_PER_SEC; + t->usec = (nano - (((uint64_t) t->sec) * NSEC_PER_SEC)) / NSEC_PER_USEC; + + return 0; +#endif /* __MACH__ */ } @@ -420,8 +444,19 @@ int os_file_exists(const char *fname) int os_fdatasync(FILE *stream) { - if (!fflush(stream)) + if (!fflush(stream)) { +#ifndef __MACH__ return fdatasync(fileno(stream)); +#else /* __MACH__ */ +#ifdef F_FULLFSYNC + /* OS X does not implement fdatasync(). */ + return fcntl(fileno(stream), F_FULLFSYNC); +#else /* F_FULLFSYNC */ +#error Neither fdatasync nor F_FULLSYNC are defined +#endif /* F_FULLFSYNC */ +#endif /* __MACH__ */ + } + return -1; } |