blob: 2271aa07fbdcb0eb9f0cd4fca4d92d22dac80697 (
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
|
/*-
* Copyright 2008 Internet Initiative Japan Inc.
*/
#include <sys/types.h>
#include <time.h>
#include <stdint.h>
#include "time_utils.h"
/**
* Return the value of system timer in nano seconds.
* Returns INT64_MIN on error.
*/
int64_t
get_nanotime(void)
{
struct timespec ts;
int64_t rval;
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
return INT64_MIN;
rval = (int64_t)ts.tv_sec * (int64_t)1000000000LL;
rval = rval + (int64_t)ts.tv_nsec;
return rval;
}
|