Commit 9e03f8e8 authored by Matthijs Mekking's avatar Matthijs Mekking 🏡
Browse files

Move dst key printtime in separate function

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.
parent 9724b6f6
......@@ -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) {
......
......@@ -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.
......
......@@ -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';
}
......@@ -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.
......
......@@ -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
......
......@@ -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';
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment