This silences LGTM warnings that these functions are not thread-safe.
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/string.h>
+#include <isc/time.h>
#include <isc/util.h>
#include <dns/keyvalues.h>
static void
printtime(dst_key_t *key, int type, const char *tag, bool epoch, FILE *stream) {
isc_result_t result;
- const char *output = NULL;
isc_stdtime_t when;
if (tag != NULL) {
} else if (epoch) {
fprintf(stream, "%d\n", (int)when);
} else {
- time_t timet = when;
- output = ctime(&timet);
- fprintf(stream, "%s", output);
+ time_t now = (time_t)when;
+#ifdef _MSC_VER
+ struct tm *tm = localtime(&now); /* Thread specific. */
+#else
+ struct tm t, *tm = localtime_r(&now, &t);
+#endif
+ unsigned int flen;
+ char timebuf[80];
+
+ flen = strftime(timebuf, sizeof(timebuf),
+ "%a %b %e %H:%M:%S %Y", tm);
+ INSIST(flen > 0U && flen < sizeof(timebuf));
+ fprintf(stream, "%s\n", timebuf);
}
}
static void
print_time(FILE *fp) {
- time_t currenttime;
+ 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) {
return;
}
- currenttime = time(NULL);
- fprintf(fp, "; File written on %s", ctime(¤ttime));
+ flen = strftime(timebuf, sizeof(timebuf), "%a %b %e %H:%M:%S %Y", tm);
+ INSIST(flen > 0U && flen < sizeof(timebuf));
+ fprintf(fp, "; File written on %s\n", timebuf);
}
static void
}
if (now != -1) {
- struct tm *tm = gmtime(&now);
+#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",
tm->tm_year + 1900);