]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Provide isc_stdtime_now(void) that returns value
authorOndřej Surý <ondrej@isc.org>
Thu, 30 Mar 2023 19:04:43 +0000 (21:04 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 31 Mar 2023 11:16:28 +0000 (13:16 +0200)
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.

lib/isc/include/isc/stdtime.h
lib/isc/stdtime.c

index 45ec50f415a8c003243b847cc2a53ed80f5d2629..0b13dd351e469868fb829c429f610e7c07259e59 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 
 #include <isc/lang.h>
+#include <isc/time.h>
 
 /*%
  * 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
index 6fecebb605bbf3c744b505d63bcfe96f1f8b3082..6f3ef49d78c26bfab51876c922c04a4e029326fd 100644 (file)
 #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));