[Toybox] [PATCH] find.c: don't assume time_t is the same as long
Rich Felker
dalias at libc.org
Sat Jan 11 08:13:13 PST 2020
I did this with a cast to long long rather than intmax_t since I think
you prefer long long, but either should be fine. This incurs a slight
binary size cost on 32-bit targets with 32-bit time_t (glibc, uclibc,
old musl) that could be eliminated via a conditional of the form:
if (sizeof(time_t)>sizeof(long))
/* print by casting to long long */
else
/* print by casting to long */
but I would prefer not uglifying the code over saving a couple bytes
of binary.
Rich
-------------- next part --------------
>From 3751201107ee8b34f3154b974adc6d5d4ae333ba Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias at aerifal.cx>
Date: Sat, 11 Jan 2020 11:07:35 -0500
Subject: [PATCH] find.c: don't assume time_t is the same as long
This is false on ILP32 targets with 64-bit time_t.
---
toys/posix/find.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 8a837385..3fb97b1c 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -636,7 +636,7 @@ static int do_find(struct dirtree *new)
} else if (ch == 'p') ll = (long)(ff = dirtree_path(new, 0));
else if (ch == 'T') {
if (*++fmt!='@') error_exit("bad -printf %%T: %%T%c", *fmt);
- sprintf(buf, "%ld.%ld", new->st.st_mtim.tv_sec,
+ sprintf(buf, "%lld.%ld", (long long)new->st.st_mtim.tv_sec,
new->st.st_mtim.tv_nsec);
ll = (long)buf;
} else if (ch == 'Z') {
--
2.21.0
More information about the Toybox
mailing list