1 /*- 2 * Copyright 2008 Internet Initiative Japan Inc. 3 */ 4 #include <sys/types.h> 5 #include <time.h> 6 #include <stdint.h> 7 8 #include "time_utils.h" 9 10 /** 11 * Return the value of system timer in nano seconds. 12 * Returns INT64_MIN on error. 13 */ 14 int64_t 15 get_nanotime(void) 16 { 17 struct timespec ts; 18 int64_t rval; 19 20 if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) 21 return INT64_MIN; 22 rval = (int64_t)ts.tv_sec * (int64_t)1000000000LL; 23 rval = rval + (int64_t)ts.tv_nsec; 24 25 return rval; 26 } 27