patch(1) problems workaround
[minix3.git] / lib / libhgfs / time.c
blob1767db27606748e20afb439fae1931df28810197
1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
3 #include "inc.h"
5 static u64_t time_offset;
7 /*===========================================================================*
8 * time_init *
9 *===========================================================================*/
10 void time_init(void)
12 /* Initialize the time conversion module.
15 /* Generate a 64-bit value for the offset to use in time conversion. The
16 * HGFS time format uses Windows' FILETIME standard, expressing time in
17 * 100ns-units since Jan 1, 1601 UTC. The value that is generated is
18 * the difference between that time and the UNIX epoch, in 100ns units.
20 /* FIXME: we currently do not take into account timezones. */
21 time_offset = (u64_t)116444736 * 1000000000;
24 /*===========================================================================*
25 * time_put *
26 *===========================================================================*/
27 void time_put(struct timespec *tsp)
29 /* Store a POSIX timestamp pointed to by the given pointer onto the RPC buffer,
30 * in HGFS timestamp format. If a NULL pointer is given, store a timestamp of
31 * zero instead.
33 u64_t hgfstime;
35 if (tsp != NULL) {
36 hgfstime = ((u64_t)tsp->tv_sec * 10000000) + (tsp->tv_nsec / 100);
37 hgfstime += time_offset;
39 RPC_NEXT32 = ex64lo(hgfstime);
40 RPC_NEXT32 = ex64hi(hgfstime);
41 } else {
42 RPC_NEXT32 = 0;
43 RPC_NEXT32 = 0;
47 /*===========================================================================*
48 * time_get *
49 *===========================================================================*/
50 void time_get(struct timespec *tsp)
52 /* Get a HGFS timestamp from the RPC buffer, convert it into a POSIX timestamp,
53 * and store the result in the given time pointer. If the given pointer is
54 * NULL, however, simply skip over the timestamp in the RPC buffer.
56 u64_t hgfstime;
57 u32_t time_lo, time_hi;
59 if (tsp != NULL) {
60 time_lo = RPC_NEXT32;
61 time_hi = RPC_NEXT32;
63 hgfstime = make64(time_lo, time_hi) - time_offset;
65 tsp->tv_sec = (unsigned long)(hgfstime / 10000000);
66 tsp->tv_nsec = (unsigned)(hgfstime % 10000000) * 100;
68 else RPC_ADVANCE(sizeof(u32_t) * 2);