This pleases linters that dislike localtime(3).
AC_CHECK_FUNCS(getopt_long)
AC_CHECK_FUNCS(getpwuid)
AC_CHECK_FUNCS(gettimeofday)
+AC_CHECK_FUNCS(localtime_r)
AC_CHECK_FUNCS(mkstemp)
AC_CHECK_FUNCS(realpath)
AC_CHECK_FUNCS(setenv)
set_up_signal_handlers();
#endif
+ // Needed for portability when using localtime_r.
+ tzset();
+
orig_args = args_init(argc, argv);
initialize();
bool parse_size_with_suffix(const char *str, uint64_t *size);
char *x_realpath(const char *path);
char *gnu_getcwd(void);
+#ifndef HAVE_LOCALTIME_R
+struct tm *localtime_r(const time_t *timep, struct tm *result);
+#endif
#ifndef HAVE_STRTOK_R
char *strtok_r(char *str, const char *delim, char **saveptr);
#endif
// Make sure that the hash sum changes if the (potential) expansion of
// __DATE__ changes.
time_t t = time(NULL);
- struct tm *now = localtime(&t);
+ struct tm now;
+ localtime_r(&t, &now);
cc_log("Found __DATE__ in %s", path);
hash_delimiter(hash, "date");
- hash_int(hash, now->tm_year);
- hash_int(hash, now->tm_mon);
- hash_int(hash, now->tm_mday);
+ hash_int(hash, now.tm_year);
+ hash_int(hash, now.tm_mon);
+ hash_int(hash, now.tm_mday);
}
if (result & HASH_SOURCE_CODE_FOUND_TIME) {
// We don't know for sure that the program actually uses the __TIME__
format_timestamp(uint64_t timestamp)
{
if (timestamp > 0) {
- struct tm *tm = localtime((time_t *)×tamp);
+ struct tm tm;
+ localtime_r((time_t *)×tamp, &tm);
char buffer[100];
- strftime(buffer, sizeof(buffer), "%c", tm);
+ strftime(buffer, sizeof(buffer), "%c", &tm);
return format(" %s", buffer);
} else {
return NULL;
printf("secondary config (readonly) %s\n",
secondary_config_path ? secondary_config_path : "");
if (last_updated > 0) {
- struct tm *tm = localtime(&last_updated);
+ struct tm tm;
+ localtime_r(&last_updated, &tm);
char timestamp[100];
- strftime(timestamp, sizeof(timestamp), "%c", tm);
+ strftime(timestamp, sizeof(timestamp), "%c", &tm);
printf("stats updated %s\n", timestamp);
}
#ifdef HAVE_GETTIMEOFDAY
if (log_updated_time) {
char timestamp[100];
- struct tm *tm;
+ struct tm tm;
struct timeval tv;
gettimeofday(&tv, NULL);
#ifdef __MINGW64_VERSION_MAJOR
- tm = localtime((time_t *)&tv.tv_sec);
+ localtime_r((time_t *)&tv.tv_sec, &tm);
#else
- tm = localtime(&tv.tv_sec);
+ localtime_r(&tv.tv_sec, &tm);
#endif
- strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", tm);
+ strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", &tm);
snprintf(prefix, sizeof(prefix),
"[%s.%06d %-5d] ", timestamp, (int)tv.tv_usec, (int)getpid());
}
}
}
+#ifndef HAVE_LOCALTIME_R
+// localtime_r replacement.
+struct tm *
+localtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *tm = localtime(timep);
+ *result = *tm;
+ return result;
+}
+#endif
+
#ifndef HAVE_STRTOK_R
// strtok_r replacement.
char *