From 5be1a96f75a7ffc46cba8c63a09a193152338366 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Mon, 13 Jan 2020 12:37:32 +0100 Subject: Use localtime_r and gmtime_r if supported Found by LGTM.com code analysis --- cpio/cpio.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'cpio') diff --git a/cpio/cpio.c b/cpio/cpio.c index 4fd394de..f8dd62c5 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -1139,6 +1139,10 @@ list_item_verbose(struct cpio *cpio, struct archive_entry *entry) const char *fmt; time_t mtime; static time_t now; + struct tm *ltime; +#ifdef HAVE_LOCALTIME_R + struct tm tmbuf; +#endif if (!now) time(&now); @@ -1186,7 +1190,12 @@ list_item_verbose(struct cpio *cpio, struct archive_entry *entry) else fmt = cpio->day_first ? "%e %b %H:%M" : "%b %e %H:%M"; #endif - strftime(date, sizeof(date), fmt, localtime(&mtime)); +#ifdef HAVE_LOCALTIME_R + ltime = localtime_r(&mtime, &tmbuf); +#else + ltime = localtime(&mtime) +#endif + strftime(date, sizeof(date), fmt, ltime); fprintf(out, "%s%3d %-8s %-8s %8s %12s %s", archive_entry_strmode(entry), -- cgit v1.2.1