#include <stdlib.h>
#include <isc/lang.h>
+#include <isc/time.h>
/*%
* It's public information that 'isc_stdtime_t' is an unsigned integral type.
ISC_LANG_BEGINDECLS
/* */
-void
-isc_stdtime_get(isc_stdtime_t *t);
+isc_stdtime_t
+isc_stdtime_now(void);
/*%<
- * Set 't' to the number of seconds since 00:00:00 UTC, January 1, 1970.
- *
- * Requires:
- *
- *\li 't' is a valid pointer.
+ * Return the number of seconds since 00:00:00 UTC, January 1, 1970.
*/
+/* Compatibility macro */
+#define isc_stdtime_get(tp) \
+ { \
+ REQUIRE(tp != NULL); \
+ *tp = isc_stdtime_now(); \
+ }
+
void
isc_stdtime_tostring(isc_stdtime_t t, char *out, size_t outlen);
/*
* 'outlen' is at least 26.
*/
-#define isc_stdtime_convert32(t, t32p) (*(t32p) = t)
-/*
- * Convert the standard time to its 32-bit version.
- */
-
ISC_LANG_ENDDECLS
#define CLOCKSOURCE CLOCK_REALTIME
#endif /* if defined(CLOCK_REALTIME_COARSE) */
-void
-isc_stdtime_get(isc_stdtime_t *t) {
- REQUIRE(t != NULL);
-
+isc_stdtime_t
+isc_stdtime_now(void) {
struct timespec ts;
if (clock_gettime(CLOCKSOURCE, &ts) == -1) {
FATAL_SYSERROR(errno, "clock_gettime()");
}
+ INSIST(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
- REQUIRE(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
-
- *t = (isc_stdtime_t)ts.tv_sec;
+ return ((isc_stdtime_t)ts.tv_sec);
}
void
REQUIRE(out != NULL);
REQUIRE(outlen >= 26);
- UNUSED(outlen);
-
/* time_t and isc_stdtime_t might be different sizes */
when = t;
INSIST((ctime_r(&when, out) != NULL));