[git commit] libbb: in @SECONDS date format, use 64-bit time if libc allows

Denys Vlasenko vda.linux at googlemail.com
Sat Nov 28 22:21:13 UTC 2020


commit: https://git.busybox.net/busybox/commit/?id=32a8f70ac1caa4037b63747c0c0a5086953ea668
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
packed_usage                                       33472   33486     +14
parse_datestr                                        919     916      -3

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/date.c | 1 +
 libbb/time.c     | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/coreutils/date.c b/coreutils/date.c
index dfc1c7663..7061f1719 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -111,6 +111,7 @@
 //usage:	)
 //usage:     "\n"
 //usage:     "\nRecognized TIME formats:"
+//usage:     "\n	@seconds_since_1970"
 //usage:     "\n	hh:mm[:ss]"
 //usage:     "\n	[YYYY.]MM.DD-hh:mm[:ss]"
 //usage:     "\n	YYYY-MM-DD hh:mm[:ss]"
diff --git a/libbb/time.c b/libbb/time.c
index e66a9cba8..86b88a414 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -90,7 +90,11 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
 		ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
 	} else
 	if (date_str[0] == '@') {
-		time_t t = bb_strtol(date_str + 1, NULL, 10);
+		time_t t;
+		if (sizeof(t) <= sizeof(long))
+			t = bb_strtol(date_str + 1, NULL, 10);
+		else /* time_t is 64 bits but longs are smaller */
+			t = bb_strtoll(date_str + 1, NULL, 10);
 		if (!errno) {
 			struct tm *lt = localtime(&t);
 			if (lt) {


More information about the busybox-cvs mailing list