From: Ben Kaduk Date: Mon, 9 Dec 2013 19:42:13 +0000 (-0500) Subject: Add some time-related helpers X-Git-Tag: openafs-devel-1_9_0~593 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=f70ab59f88aa41074c9f075368137bd663cc8bce Add some time-related helpers RXGK_NOW(), a quick routine to get the current timestamp as an rxgkTime, and secondsToRxgkTime for the more general scaling factor. Change-Id: I0051b5c8e5ad61e35431d97454bf2741daba90cb Reviewed-on: https://gerrit.openafs.org/10566 Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Mark Vitale Reviewed-by: Michael Meffie Reviewed-by: Marcio Brito Barbosa Reviewed-by: Benjamin Kaduk --- diff --git a/src/rxgk/rxgk.h b/src/rxgk/rxgk.h index 56dbf67..930e69a 100644 --- a/src/rxgk/rxgk.h +++ b/src/rxgk/rxgk.h @@ -42,6 +42,25 @@ /* Pull in the protocol description */ #include +/* rxgkTime is defined in rxgk_int.xg. rxgkTime values are unix timestamps, but + * in 100-nanosecond units. */ + +/* Helpers to avoid having to count zeros. */ +static_inline rxgkTime secondsToRxgkTime(afs_uint64 seconds) { + return seconds * (rxgkTime)10000000; +} +static_inline afs_uint64 rxgkTimeToSeconds(rxgkTime atime) { + return (afs_uint64)atime / 10000000; +} + +/** Get the current timestamp as an rxgkTime. */ +static_inline rxgkTime RXGK_NOW(void) +{ + struct timeval tv; + osi_GetTime(&tv); + return secondsToRxgkTime(tv.tv_sec) + (rxgkTime)tv.tv_usec * 10; +} + /* rxgk_key is an opaque type to wrap our RFC3961 implementation's concept * of a key. It has (at least) the keyblock and length, and enctype. */ typedef void * rxgk_key;