summaryrefslogtreecommitdiff
path: root/src/time/clock.c
blob: c348e39836caec86425652d6e0e3259ff9c05a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <time.h>
#include <limits.h>

int __clock_gettime(clockid_t, struct timespec *);

clock_t clock()
{
	struct timespec ts;

	if (__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts))
		return -1;

	if (ts.tv_sec > LONG_MAX/1000000
	 || ts.tv_nsec/1000 > LONG_MAX-1000000*ts.tv_sec)
		return -1;

	return ts.tv_sec*1000000 + ts.tv_nsec/1000;
}