aboutsummaryrefslogtreecommitdiffstats
path: root/cpio
diff options
context:
space:
mode:
Diffstat (limited to 'cpio')
-rw-r--r--cpio/cpio.c22
-rw-r--r--cpio/test/test_basic.c14
-rw-r--r--cpio/test/test_format_newc.c15
3 files changed, 38 insertions, 13 deletions
diff --git a/cpio/cpio.c b/cpio/cpio.c
index 4fd394dea5f1..da5c39860018 100644
--- a/cpio/cpio.c
+++ b/cpio/cpio.c
@@ -1139,6 +1139,14 @@ list_item_verbose(struct cpio *cpio, struct archive_entry *entry)
const char *fmt;
time_t mtime;
static time_t now;
+ struct tm *ltime;
+#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S)
+ struct tm tmbuf;
+#endif
+#if defined(HAVE__LOCALTIME64_S)
+ errno_t terr;
+ __time64_t tmptime;
+#endif
if (!now)
time(&now);
@@ -1186,7 +1194,19 @@ 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));
+#if defined(HAVE_LOCALTIME_R)
+ ltime = localtime_r(&mtime, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = mtime;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ ltime = NULL;
+ else
+ ltime = &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),
diff --git a/cpio/test/test_basic.c b/cpio/test/test_basic.c
index a8fedf89e968..b716253408fa 100644
--- a/cpio/test/test_basic.c
+++ b/cpio/test/test_basic.c
@@ -33,15 +33,15 @@ verify_files(const char *msg)
*/
/* Regular file with 2 links. */
- failure(msg);
+ failure("%s", msg);
assertIsReg("file", 0644);
- failure(msg);
+ failure("%s", msg);
assertFileSize("file", 10);
- failure(msg);
+ failure("%s", msg);
assertFileNLinks("file", 2);
/* Another name for the same file. */
- failure(msg);
+ failure("%s", msg);
assertIsHardlink("linkfile", "file");
/* Symlink */
@@ -49,11 +49,11 @@ verify_files(const char *msg)
assertIsSymlink("symlink", "file", 0);
/* Another file with 1 link and different permissions. */
- failure(msg);
+ failure("%s", msg);
assertIsReg("file2", 0777);
- failure(msg);
+ failure("%s", msg);
assertFileSize("file2", 10);
- failure(msg);
+ failure("%s", msg);
assertFileNLinks("file2", 1);
/* dir */
diff --git a/cpio/test/test_format_newc.c b/cpio/test/test_format_newc.c
index 6c981f6ac139..49387a73580b 100644
--- a/cpio/test/test_format_newc.c
+++ b/cpio/test/test_format_newc.c
@@ -205,9 +205,11 @@ DEFINE_TEST(test_format_newc)
gid = from_hex(e + 30, 8); /* gid */
assertEqualMem(e + 38, "00000003", 8); /* nlink */
t = from_hex(e + 46, 8); /* mtime */
- failure("t=0x%08x now=0x%08x=%d", t, now, now);
+ failure("t=%#08jx now=%#08jx=%jd", (intmax_t)t, (intmax_t)now,
+ (intmax_t)now);
assert(t <= now); /* File wasn't created in future. */
- failure("t=0x%08x now - 2=0x%08x = %d", t, now - 2, now - 2);
+ failure("t=%#08jx now - 2=%#08jx=%jd", (intmax_t)t, (intmax_t)now - 2,
+ (intmax_t)now - 2);
assert(t >= now - 2); /* File was created w/in last 2 secs. */
failure("newc format stores body only with last appearance of a link\n"
" first appearance should be empty, so this file size\n"
@@ -243,7 +245,8 @@ DEFINE_TEST(test_format_newc)
assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
assertEqualMem(e + 38, "00000001", 8); /* nlink */
t2 = from_hex(e + 46, 8); /* mtime */
- failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2);
+ failure("First entry created at t=%#08jx this entry created"
+ " at t2=%#08jx", (intmax_t)t, (intmax_t)t2);
assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
assertEqualMem(e + 54, "00000005", 8); /* File size */
fs = from_hex(e + 54, 8);
@@ -278,7 +281,8 @@ DEFINE_TEST(test_format_newc)
assertEqualInt(nlinks("dir"), from_hex(e + 38, 8)); /* nlinks */
#endif
t2 = from_hex(e + 46, 8); /* mtime */
- failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2);
+ failure("First entry created at t=%#08jx this entry created at"
+ "t2=%#08jx", (intmax_t)t, (intmax_t)t2);
assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
assertEqualMem(e + 54, "00000000", 8); /* File size */
fs = from_hex(e + 54, 8);
@@ -311,7 +315,8 @@ DEFINE_TEST(test_format_newc)
assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
assertEqualMem(e + 38, "00000003", 8); /* nlink */
t2 = from_hex(e + 46, 8); /* mtime */
- failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2);
+ failure("First entry created at t=%#08jx this entry created at"
+ "t2=%#08jx", (intmax_t)t, (intmax_t)t2);
assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
assertEqualInt(10, from_hex(e + 54, 8)); /* File size */
fs = from_hex(e + 54, 8);