#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>
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(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)
snprintf(buf + flen, len - flen,
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(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);
}
isc_time_formatISO8601L(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(len > 0);
now = (time_t)t->seconds;
+#ifdef ISC_PLATFORM_USETHREADS
+ flen = strftime(buf, len, "%Y-%m-%dT%H:%M:%S", localtime_r(&now, &tm));
+#else
flen = strftime(buf, len, "%Y-%m-%dT%H:%M:%S", localtime(&now));
+#endif
INSIST(flen < len);
}
isc_time_formatISO8601Lms(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(len > 0);
now = (time_t)t->seconds;
+#ifdef ISC_PLATFORM_USETHREADS
+ flen = strftime(buf, len, "%Y-%m-%dT%H:%M:%S", localtime_r(&now, &tm));
+#else
flen = strftime(buf, len, "%Y-%m-%dT%H:%M:%S", localtime(&now));
+#endif
INSIST(flen < len);
if (flen > 0U && len - flen >= 6) {
snprintf(buf + flen, len - flen, ".%03u",
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(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);
}
isc_time_formatISO8601ms(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(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);
if (flen > 0U && len - flen >= 5) {
flen -= 1; /* rewind one character (Z) */
{
time_t now;
unsigned int flen;
+#ifdef ISC_PLATFORM_USETHREADS
+ struct tm tm;
+#endif
REQUIRE(len > 0);
now = (time_t)t->seconds;
+#ifdef ISC_PLATFORM_USETHREADS
+ flen = strftime(buf, len, "%Y%m%d%H%M%S", gmtime_r(&now, &tm));
+#else
flen = strftime(buf, len, "%Y%m%d%H%M%S", gmtime(&now));
+#endif
INSIST(flen < len);
if (flen > 0U && len - flen >= 5) {
flen -= 1; /* rewind one character (Z) */