summaryrefslogtreecommitdiff
path: root/cpio
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2020-01-13 12:37:32 +0100
committerMartin Matuska <martin@matuska.org>2020-01-13 13:39:58 +0100
commit5be1a96f75a7ffc46cba8c63a09a193152338366 (patch)
tree99f2f4552728289ccd0b6b6391c122c38d3df173 /cpio
parent2aaf7c5e88d495a0705e965519bfe9096765df6d (diff)
downloadlibarchive-5be1a96f75a7ffc46cba8c63a09a193152338366.tar.gz
Use localtime_r and gmtime_r if supported
Found by LGTM.com code analysis
Diffstat (limited to 'cpio')
-rw-r--r--cpio/cpio.c11
1 files changed, 10 insertions, 1 deletions
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),