From 24f746bf82ec609f73d09028d4eb6b0447a060eb Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 30 May 2021 15:52:55 +0200 Subject: [PATCH] Use localtime_r() when available No effect on the monothread context, but avoid warnings from static analysis. --- cmdline/snapraid.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 9e5e97b3..f92ae1e6 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -131,13 +131,20 @@ void log_open(const char* file) char text_D[32]; time_t t; struct tm* tm; +#if HAVE_LOCALTIME_R + struct tm tm_res; +#endif /* leave stdlog at 0 if not specified */ if (file == 0) return; t = time(0); +#if HAVE_LOCALTIME_R + tm = localtime_r(&t, &tm_res); +#else tm = localtime(&t); +#endif if (tm) { strftime(text_T, sizeof(text_T), "%H%M%S", tm); strftime(text_D, sizeof(text_T), "%Y%m%d", tm); @@ -552,6 +559,9 @@ int main(int argc, char* argv[]) int period; time_t t; struct tm* tm; +#if HAVE_LOCALTIME_R + struct tm tm_res; +#endif int i; test(argc, argv); @@ -1225,7 +1235,11 @@ int main(int argc, char* argv[]) /* print generic info into the log */ t = time(0); +#if HAVE_LOCALTIME_R + tm = localtime_r(&t, &tm_res); +#else tm = localtime(&t); +#endif log_tag("version:%s\n", PACKAGE_VERSION); log_tag("unixtime:%" PRIi64 "\n", (int64_t)t); if (tm) {