xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/time.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <time.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <stdlib.h>
8 
9 time_t
10 time(time_t *tp)
11 {
12 	char b[20];
13 	static int f = -1;
14 	time_t t;
15 
16 	memset(b, 0, sizeof(b));
17 	if(f < 0)
18 		f = open("/dev/time", O_RDONLY);
19 	if(f >= 0) {
20 		lseek(f, 0, 0);
21 		read(f, b, sizeof(b));
22 	}
23 	t = atol(b);
24 	if(tp)
25 		*tp = t;
26 	return t;
27 }
28