Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

44 lines
1.4 KiB

/*
* Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
* Copyright (c) 2014 Brent Cook <bcook@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <mach/mach_time.h>
#include <sys/time.h>
#include <stdint.h>
#include <time.h>
int
clock_gettime(clockid_t clk_id, struct timespec *ts)
{
static uint64_t timebase_factor = 0;
mach_timebase_info_data_t timebase_info;
uint64_t nsec;
if (clk_id != CLOCK_REALTIME)
return -1; /* not implemented */
if (timebase_factor == 0) {
mach_timebase_info(&timebase_info);
timebase_factor = timebase_info.numer / timebase_info.denom;
}
nsec = mach_absolute_time() * timebase_factor;
ts->tv_sec = nsec / 1000000000UL;
ts->tv_nsec = nsec % 1000000000UL;
return 0;
}