summaryrefslogtreecommitdiff
path: root/tar
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 /tar
parent2aaf7c5e88d495a0705e965519bfe9096765df6d (diff)
downloadlibarchive-5be1a96f75a7ffc46cba8c63a09a193152338366.tar.gz
Use localtime_r and gmtime_r if supported
Found by LGTM.com code analysis
Diffstat (limited to 'tar')
-rw-r--r--tar/util.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/tar/util.c b/tar/util.c
index 662db5ba..85c5446a 100644
--- a/tar/util.c
+++ b/tar/util.c
@@ -666,6 +666,10 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
const char *fmt;
time_t tim;
static time_t now;
+ struct tm *ltime;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tmbuf;
+#endif
/*
* We avoid collecting the entire list in memory at once by
@@ -737,7 +741,12 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
fmt = bsdtar->day_first ? DAY_FMT " %b %Y" : "%b " DAY_FMT " %Y";
else
fmt = bsdtar->day_first ? DAY_FMT " %b %H:%M" : "%b " DAY_FMT " %H:%M";
- strftime(tmp, sizeof(tmp), fmt, localtime(&tim));
+#ifdef HAVE_LOCALTIME_R
+ ltime = localtime_r(&tim, &tmbuf);
+#else
+ ltime = localtime(&tim);
+#endif
+ strftime(tmp, sizeof(tmp), fmt, ltime);
fprintf(out, " %s ", tmp);
safe_fprintf(out, "%s", archive_entry_pathname(entry));