}
printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
time(&tnow);
-#if !defined(WIN32)
(void)localtime_r(&tnow, &tmnow);
-#else /* if !defined(WIN32) */
- tmnow = *localtime(&tnow);
-#endif /* if !defined(WIN32) */
#ifdef WIN32
/*
} else if (epoch) {
fprintf(stream, "%d\n", (int)when);
} else {
- time_t now = (time_t)when;
-#ifdef _MSC_VER
- struct tm *tm = localtime(&now); /* Thread specific. */
-#else
+ time_t now = when;
struct tm t, *tm = localtime_r(&now, &t);
-#endif
unsigned int flen;
char timebuf[80];
+ if (tm == NULL) {
+ fprintf(stream, "INVALID\n");
+ return;
+ }
+
flen = strftime(timebuf, sizeof(timebuf),
"%a %b %e %H:%M:%S %Y", tm);
INSIST(flen > 0U && flen < sizeof(timebuf));
static void
print_time(FILE *fp) {
time_t currenttime = time(NULL);
-#ifdef _MSC_VER
- struct tm *tm = localtime(¤ttime); /* Thread specific. */
-#else
struct tm t, *tm = localtime_r(¤ttime, &t);
-#endif
unsigned int flen;
char timebuf[80];
- if (outputformat != dns_masterformat_text) {
+ if (tm == NULL || outputformat != dns_masterformat_text) {
return;
}
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
#include <windows.h>
#include <isc/lang.h>
}
}
+inline struct tm *
+gmtime_r(const time_t *clock, struct tm *result) {
+ errno_t ret = gmtime_s(result, clock);
+ if (ret != 0) {
+ errno = ret;
+ return (NULL);
+ }
+ return (result);
+}
+
ISC_LANG_ENDDECLS
#endif /* DNS_GEN_WIN32_H */
}
if (now != -1) {
-#ifdef _MSC_VER
- struct tm *tm = gmtime(&now); /* Thread specific. */
-#else
struct tm t, *tm = gmtime_r(&now, &t);
-#endif
if (tm != NULL && tm->tm_year > 104) {
n = snprintf(year, sizeof(year), "-%d",
static isc_stdtime_t
epoch_to_yyyymmdd(time_t when) {
- struct tm *tm;
-
-#if !defined(WIN32)
- struct tm tm0;
- tm = localtime_r(&when, &tm0);
-#else /* if !defined(WIN32) */
- tm = localtime(&when);
-#endif /* if !defined(WIN32) */
+ struct tm t, *tm = localtime_r(&when, &t);
+ if (tm == NULL) {
+ return (0);
+ }
return (((tm->tm_year + 1900) * 10000) + ((tm->tm_mon + 1) * 100) +
tm->tm_mday);
}
#ifndef ISC_TIME_H
#define ISC_TIME_H 1
+#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <windows.h>
#include <isc/lang.h>
#include <isc/types.h>
+/***
+ *** POSIX Shims
+ ***/
+
+inline struct tm *
+gmtime_r(const time_t *clock, struct tm *result) {
+ errno_t ret = gmtime_s(result, clock);
+ if (ret != 0) {
+ errno = ret;
+ return (NULL);
+ }
+ return (result);
+}
+
+inline struct tm *
+localtime_r(const time_t *clock, struct tm *result) {
+ errno_t ret = localtime_s(result, clock);
+ if (ret != 0) {
+ errno = ret;
+ return (NULL);
+ }
+ return (result);
+}
+
/***
*** Intervals
***/