Add some time-related helpers 66/10566/16
authorBen Kaduk <kaduk@mit.edu>
Mon, 9 Dec 2013 19:42:13 +0000 (14:42 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Tue, 27 Mar 2018 17:25:58 +0000 (13:25 -0400)
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 <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/rxgk/rxgk.h

index 56dbf67..930e69a 100644 (file)
 /* Pull in the protocol description */
 #include <rx/rxgk_int.h>
 
+/* 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;