Remove building with NOCRYPTO option
[minix.git] / minix / lib / libsys / clock_time.c
blob80c82e560f723264c7b9956ecc54e18b1093fa5a
2 #include "sysutil.h"
3 #include <sys/time.h>
5 /*
6 * This routine returns the time in seconds since 1.1.1970. MINIX is an
7 * astrophysically naive system that assumes the earth rotates at a constant
8 * rate and that such things as leap seconds do not exist. If a non-NULL
9 * pointer to a timespec structure is given, that structure is filled with
10 * the current time in subsecond precision.
12 time_t
13 clock_time(struct timespec *tv)
15 struct minix_kerninfo *minix_kerninfo;
16 uint32_t system_hz;
17 clock_t realtime;
18 time_t boottime, sec;
20 minix_kerninfo = get_minix_kerninfo();
22 /* We assume atomic 32-bit field retrieval. TODO: 64-bit support. */
23 boottime = minix_kerninfo->kclockinfo->boottime;
24 realtime = minix_kerninfo->kclockinfo->realtime;
25 system_hz = minix_kerninfo->kclockinfo->hz;
27 sec = boottime + realtime / system_hz;
29 if (tv != NULL) {
30 tv->tv_sec = sec;
33 * We do not want to overflow, and system_hz can be as high as
34 * 50kHz.
36 if (system_hz < LONG_MAX / 40000)
37 tv->tv_nsec = (realtime % system_hz) * 40000 /
38 system_hz * 25000;
39 else
40 tv->tv_nsec = 0; /* bad, but what's better? */
43 return sec;