#include <stdio.h>
#include <string.h>
#include <time.h>
#include <isc/region.h>
#include <isc/serial.h>
#include <isc/result.h>
#include <dns/time.h>
static isc_result_t
dns_time64_totext(time_t t, isc_buffer_t *target) {
struct tm *tm;
char buf[sizeof("YYYYMMDDHHMMSS")];
size_t l;
isc_region_t region;
tm = gmtime(&t);
if ((l = strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", tm)) == 0)
return (ISC_R_NOSPACE);
isc_buffer_availableregion(target, ®ion);
if (l > region.length)
return (ISC_R_NOSPACE);
memmove(region.base, buf, l);
isc_buffer_add(target, l);
return (ISC_R_SUCCESS);
}
static time_t
dns_time64_from32(uint32_t value) {
uint32_t now32;
time_t start;
time_t t;
time(&start);
now32 = (uint32_t) start;
if (isc_serial_gt(value, now32))
t = start + (value - now32);
else
t = start - (now32 - value);
return (t);
}
isc_result_t
dns_time32_totext(uint32_t value, isc_buffer_t *target) {
return (dns_time64_totext(dns_time64_from32(value), target));
}