From: Ondřej Surý Date: Thu, 30 Mar 2023 19:04:43 +0000 (+0200) Subject: Provide isc_stdtime_now(void) that returns value X-Git-Tag: v9.19.12~44^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c11af0448a56bb1f0fefc2646c77fcdca6afc82f;p=thirdparty%2Fbind9.git Provide isc_stdtime_now(void) that returns value As isc_stdtime_get() cannot fail, the API seems to be too complicated, add new isc_stdtime_now() that returns the unixtime as a return value. --- diff --git a/lib/isc/include/isc/stdtime.h b/lib/isc/include/isc/stdtime.h index 45ec50f415a..0b13dd351e4 100644 --- a/lib/isc/include/isc/stdtime.h +++ b/lib/isc/include/isc/stdtime.h @@ -19,6 +19,7 @@ #include #include +#include /*% * It's public information that 'isc_stdtime_t' is an unsigned integral type. @@ -29,16 +30,19 @@ typedef uint32_t isc_stdtime_t; 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); /* @@ -53,9 +57,4 @@ 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 diff --git a/lib/isc/stdtime.c b/lib/isc/stdtime.c index 6fecebb605b..6f3ef49d78c 100644 --- a/lib/isc/stdtime.c +++ b/lib/isc/stdtime.c @@ -33,19 +33,16 @@ #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 @@ -55,8 +52,6 @@ isc_stdtime_tostring(isc_stdtime_t t, char *out, size_t outlen) { 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));