diff options
| author | 2019-12-17 01:46:30 +0000 | |
|---|---|---|
| committer | 2019-12-17 01:46:30 +0000 | |
| commit | 3ef32adf69b1fed9e0363dd1f2116627f09e6af3 (patch) | |
| tree | 4d9d566691647dad37619d7bd9d1c7114f554bbe /usr.sbin/bind/lib/isc/unix/time.c | |
| parent | Add support for NCT6775F, NCT5104D, NCT6779D, NCT679[1235]D sensors. (diff) | |
| download | wireguard-openbsd-3ef32adf69b1fed9e0363dd1f2116627f09e6af3.tar.xz wireguard-openbsd-3ef32adf69b1fed9e0363dd1f2116627f09e6af3.zip | |
update to 9.10.8-P1, last isc-licensed release
Diffstat (limited to 'usr.sbin/bind/lib/isc/unix/time.c')
| -rw-r--r-- | usr.sbin/bind/lib/isc/unix/time.c | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/usr.sbin/bind/lib/isc/unix/time.c b/usr.sbin/bind/lib/isc/unix/time.c index f8aabecdda7..04566e6b012 100644 --- a/usr.sbin/bind/lib/isc/unix/time.c +++ b/usr.sbin/bind/lib/isc/unix/time.c @@ -1,6 +1,5 @@ /* - * Copyright (C) 2004-2008, 2011, 2012, 2014, 2015 Internet Systems Consortium, Inc. ("ISC") - * Copyright (C) 1998-2001, 2003 Internet Software Consortium. + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: time.c,v 1.5 2019/12/16 16:16:27 deraadt Exp $ */ +/* $Id: time.c,v 1.6 2019/12/17 01:46:37 sthen Exp $ */ /*! \file */ @@ -30,6 +29,7 @@ #include <sys/time.h> /* Required for struct timeval on some platforms. */ #include <isc/log.h> +#include <isc/platform.h> #include <isc/print.h> #include <isc/strerror.h> #include <isc/string.h> @@ -384,31 +384,53 @@ void isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) { time_t now; unsigned int flen; +#ifdef ISC_PLATFORM_USETHREADS + struct tm tm; +#endif + REQUIRE(t != NULL); + INSIST(t->nanoseconds < NS_PER_S); + REQUIRE(buf != NULL); REQUIRE(len > 0); now = (time_t) t->seconds; +#ifdef ISC_PLATFORM_USETHREADS + flen = strftime(buf, len, "%d-%b-%Y %X", localtime_r(&now, &tm)); +#else flen = strftime(buf, len, "%d-%b-%Y %X", localtime(&now)); +#endif INSIST(flen < len); - if (flen != 0) + if (flen != 0) { snprintf(buf + flen, len - flen, ".%03u", t->nanoseconds / 1000000); - else - snprintf(buf, len, "99-Bad-9999 99:99:99.999"); + } else { + strlcpy(buf, "99-Bad-9999 99:99:99.999", len); + } } void isc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) { time_t now; unsigned int flen; +#ifdef ISC_PLATFORM_USETHREADS + struct tm tm; +#endif + REQUIRE(t != NULL); + INSIST(t->nanoseconds < NS_PER_S); + REQUIRE(buf != NULL); REQUIRE(len > 0); /* * 5 spaces, 1 comma, 3 GMT, 2 %d, 4 %Y, 8 %H:%M:%S, 3+ %a, 3+ %b (29+) */ now = (time_t)t->seconds; +#ifdef ISC_PLATFORM_USETHREADS + flen = strftime(buf, len, "%a, %d %b %Y %H:%M:%S GMT", + gmtime_r(&now, &tm)); +#else flen = strftime(buf, len, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&now)); +#endif INSIST(flen < len); } @@ -420,6 +442,7 @@ isc_time_parsehttptimestamp(char *buf, isc_time_t *t) { REQUIRE(buf != NULL); REQUIRE(t != NULL); + p = isc_tm_strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm); if (p == NULL) return (ISC_R_UNEXPECTED); @@ -434,10 +457,20 @@ void isc_time_formatISO8601(const isc_time_t *t, char *buf, unsigned int len) { time_t now; unsigned int flen; +#ifdef ISC_PLATFORM_USETHREADS + struct tm tm; +#endif + REQUIRE(t != NULL); + INSIST(t->nanoseconds < NS_PER_S); + REQUIRE(buf != NULL); REQUIRE(len > 0); now = (time_t)t->seconds; +#ifdef ISC_PLATFORM_USETHREADS + flen = strftime(buf, len, "%Y-%m-%dT%H:%M:%SZ", gmtime_r(&now, &tm)); +#else flen = strftime(buf, len, "%Y-%m-%dT%H:%M:%SZ", gmtime(&now)); +#endif INSIST(flen < len); } |
