blob: 81025370b6f5011d46fe2efa82e67f7d04add757 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/*
* Simulate ANSI/POSIX conformance on platforms that don't have it
*
* This file is Copyright (c) 2010 by the GPSD project
* BSD terms apply: see the file COPYING in the distribution root for details.
*/
#include <time.h>
#include <sys/time.h>
#include "compiler.h"
#ifndef HAVE_CLOCK_GETTIME
/*
* Note that previous versions of this code made use of clock_get_time()
* on OSX, as a way to get time of day with nanosecond resolution. But
* it turns out that clock_get_time() only has microsecond resolution,
* in spite of the data format, and it's also substantially slower than
* gettimeofday(). Thus, it makes no sense to do anything special for OSX.
*/
int clock_gettime(clockid_t clk_id UNUSED, struct timespec *ts)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0)
return -1;
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * 1000;
return 0;
}
#endif /* HAVE_CLOCK_GETTIME */
/* end */
|