Skip to content
Snippets Groups Projects
Commit ed5d4421 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

time: use gettimeofday if clock_gettime not available (OS X < Sierra)

parent 4d449374
No related branches found
No related tags found
1 merge request!664time: use gettimeofday if clock_gettime not available (OS X < Sierra)
Pipeline #
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,11 +15,22 @@
*/
#include "contrib/time.h"
#ifndef HAVE_CLOCK_GETTIME
#include <sys/time.h>
#endif
struct timespec time_now(void)
{
struct timespec result = { 0 };
#ifdef HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_MONOTONIC, &result);
#else // OS X < Sierra fallback.
struct timeval tmp = { 0 };
gettimeofday(&tmp, NULL);
result.tv_sec = tmp.tv_sec;
result.tv_nsec = 1000 * tmp.tv_usec;
#endif
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment