summaryrefslogtreecommitdiff
path: root/sys/src/libc/9sys/nsec.c
blob: 13fc44d5bc660b6e750e1097618df857139737ed (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
#include <u.h>
#include <libc.h>

static uvlong order = 0x0001020304050607ULL;

static void
be2vlong(vlong *to, uchar *f)
{
	uchar *t, *o;
	int i;

	t = (uchar*)to;
	o = (uchar*)&order;
	for(i = 0; i < sizeof order; i++)
		t[o[i]] = f[i];
}

vlong
nsec(void)
{
	uchar b[8];
	vlong t;
	int fd;

	t = 0;
	fd = open("/dev/bintime", OREAD);
	if(fd >= 0){
		if(pread(fd, b, sizeof b, 0) == sizeof b)
			be2vlong(&t, b);
		close(fd);
	}
	return t;
}