]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move dst key printtime in separate function
authorMatthijs Mekking <matthijs@isc.org>
Wed, 17 Jun 2020 12:00:09 +0000 (14:00 +0200)
committerMatthijs Mekking <matthijs@isc.org>
Tue, 30 Jun 2020 07:51:04 +0000 (09:51 +0200)
I'd like to use the same functionality (pretty print the datetime
of keytime metadata) in the 'rndc dnssec -status' command.  So it is
better that this logic is done in a separate function.

Since the stdtime.c code have differernt files for unix and win32,
I think the "#ifdef WIN32" define can be dropped.

lib/dns/dst_api.c
lib/isc/unix/include/isc/stdtime.h
lib/isc/unix/stdtime.c
lib/isc/win32/include/isc/stdtime.h
lib/isc/win32/libisc.def.in
lib/isc/win32/stdtime.c

index 65afc771d362a932fd5c05b25bc6aa1176e7bf23..7d7940a85159f7f867f7dfd559323da18387f6bf 100644 (file)
@@ -1906,7 +1906,6 @@ printtime(const dst_key_t *key, int type, const char *tag, FILE *stream) {
        isc_result_t result;
        char output[26]; /* Minimum buffer as per ctime_r() specification. */
        isc_stdtime_t when;
-       time_t t;
        char utc[sizeof("YYYYMMDDHHSSMM")];
        isc_buffer_t b;
        isc_region_t r;
@@ -1916,18 +1915,7 @@ printtime(const dst_key_t *key, int type, const char *tag, FILE *stream) {
                return;
        }
 
-       /* time_t and isc_stdtime_t might be different sizes */
-       t = when;
-#ifdef WIN32
-       if (ctime_s(output, sizeof(output), &t) != 0) {
-               goto error;
-       }
-#else  /* ifdef WIN32 */
-       if (ctime_r(&t, output) == NULL) {
-               goto error;
-       }
-#endif /* ifdef WIN32 */
-
+       isc_stdtime_tostring(when, output, sizeof(output));
        isc_buffer_init(&b, utc, sizeof(utc));
        result = dns_time32_totext(when, &b);
        if (result != ISC_R_SUCCESS) {
index 0503a28501a5bdb886cfc6f9f9af30c4e353edff..08d737ee8c00dfa5c6504750a1d810a2c6824898 100644 (file)
@@ -15,6 +15,7 @@
 /*! \file */
 
 #include <inttypes.h>
+#include <stdlib.h>
 
 #include <isc/lang.h>
 
@@ -37,6 +38,20 @@ isc_stdtime_get(isc_stdtime_t *t);
  *\li  't' is a valid pointer.
  */
 
+void
+isc_stdtime_tostring(isc_stdtime_t t, char *out, size_t outlen);
+/*
+ * Convert 't' into a null-terminated string of the form
+ * "Wed Jun 30 21:49:08 1993". Store the string in the 'out'
+ * buffer.
+ *
+ * Requires:
+ *
+ *     't' is a valid time.
+ *     'out' is a valid pointer.
+ *     'outlen' is at least 26.
+ */
+
 #define isc_stdtime_convert32(t, t32p) (*(t32p) = t)
 /*
  * Convert the standard time to its 32-bit version.
index e3fefad500461de524659aaeaf79474d47b6e226..24c071d76c315f95d80100f8a2d923de1bae5eb3 100644 (file)
@@ -49,3 +49,18 @@ isc_stdtime_get(isc_stdtime_t *t) {
 
        *t = (isc_stdtime_t)ts.tv_sec;
 }
+
+void
+isc_stdtime_tostring(isc_stdtime_t t, char *out, size_t outlen) {
+       time_t when;
+
+       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));
+       *(out + strlen(out) - 1) = '\0';
+}
index 5a845bd55f883885150ca73a8523416d01668c4b..74ad0151fc32b0307840a4dc802f19cffe3f5d2c 100644 (file)
@@ -13,6 +13,7 @@
 #define ISC_STDTIME_H 1
 
 #include <inttypes.h>
+#include <stdlib.h>
 
 #include <isc/lang.h>
 
@@ -35,6 +36,20 @@ isc_stdtime_get(isc_stdtime_t *t);
  *     't' is a valid pointer.
  */
 
+void
+isc_stdtime_tostring(isc_stdtime_t t, char *out, size_t outlen);
+/*
+ * Convert 't' into a null-terminated string of the form
+ * "Wed Jun 30 21:49:08 1993". Store the string in the 'out'
+ * buffer.
+ *
+ * Requires:
+ *
+ *     't' is a valid time.
+ *     'out' is a valid pointer.
+ *     'outlen' is at least 26.
+ */
+
 #define isc_stdtime_convert32(t, t32p) (*(t32p) = t)
 /*
  * Convert the standard time to its 32-bit version.
index 4d6705feec0faeb8edbe6e29966de055c353b715..3f37ede289e826ec020f17dd815be4491439a6a3 100644 (file)
@@ -605,6 +605,7 @@ isc_stdio_sync
 isc_stdio_tell
 isc_stdio_write
 isc_stdtime_get
+isc_stdtime_tostring
 isc_string_strerror_r
 isc_symtab_count
 isc_symtab_create
index 55bd1239529dd71868fe7b04d374e4a7fa60e6f5..23364624ae79eb3a3ffa3871294d0858515d9c16 100644 (file)
@@ -25,3 +25,17 @@ isc_stdtime_get(isc_stdtime_t *t) {
 
        (void)_time32(t);
 }
+
+void
+isc_stdtime_tostring(isc_stdtime_t t, char *out, size_t outlen) {
+       time_t when;
+
+       REQUIRE(out != NULL);
+       /* Minimum buffer as per ctime_r() specification. */
+       REQUIRE(outlen >= 26);
+
+       /* time_t and isc_stdtime_t might be different sizes */
+       when = t;
+       INSIST((ctime_s(out, outlen, &when) == 0));
+       *(out + strlen(out) - 1) = '\0';
+}