From 9eefd2d5ebde2a2764dd8a21ab67ccfefaa78970 Mon Sep 17 00:00:00 2001 From: Ola x Nilsson Date: Tue, 16 Apr 2024 11:57:33 +0200 Subject: [PATCH] tests: Handle various time_t sizes in printf The members of the timeval struct are both signed (defined by POSIX) and typically both 64 bits on a system where time_t is 64 bits. This is possible also on 32 bit systems where time_t is larger to handle the 2038 problem. It's practically impossible to find a type and printf format that works even on all glibc systems. Play it safe and always use printf with intmax_t. --- tests/kern/pathwalk.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/kern/pathwalk.c b/tests/kern/pathwalk.c index d342b267..3622e1c5 100644 --- a/tests/kern/pathwalk.c +++ b/tests/kern/pathwalk.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -149,8 +150,8 @@ main (int argc, char *argv[]) err_exit ("gettimeofday"); timersub (&t2, &t1, &elapsed); if (!qflag) - msg ("Created %d objects in %lu.%.3lus", length * files + 1, - elapsed.tv_sec, elapsed.tv_usec / 1000); + msg ("Created %d objects in %jd.%.3jds", length * files + 1, + (intmax_t)elapsed.tv_sec, (intmax_t)elapsed.tv_usec / 1000); } /* Test @@ -164,9 +165,9 @@ main (int argc, char *argv[]) err_exit ("gettimeofday"); timersub (&t2, &t1, &elapsed); if (!qflag) - msg ("Found %d/%d files in %d directories in %lu.%.3lus", + msg ("Found %d/%d files in %d directories in %jd.%.3jds", count, 1, length, - elapsed.tv_sec, elapsed.tv_usec / 1000); + (intmax_t)elapsed.tv_sec, (intmax_t)elapsed.tv_usec / 1000); } if (gettimeofday (&t1, NULL) < 0) err_exit ("gettimeofday"); @@ -175,8 +176,8 @@ main (int argc, char *argv[]) err_exit ("gettimeofday"); timersub (&t2, &t1, &elapsed); if (!qflag) - msg ("Found %d/%d files in %d directories in %lu.%.3lus", - count, files, length, elapsed.tv_sec, elapsed.tv_usec / 1000); + msg ("Found %d/%d files in %d directories in %jd.%.3jds", + count, files, length, (intmax_t)elapsed.tv_sec, (intmax_t)elapsed.tv_usec / 1000); } /* Remove root + fs objects. @@ -191,8 +192,8 @@ main (int argc, char *argv[]) err_exit ("gettimeofday"); timersub (&t2, &t1, &elapsed); if (!qflag) - msg ("Removed %d objects in %lu.%.3lus", length * files + 1, - elapsed.tv_sec, elapsed.tv_usec / 1000); + msg ("Removed %d objects in %jd.%.3jds", length * files + 1, + (intmax_t)elapsed.tv_sec, (intmax_t)elapsed.tv_usec / 1000); } searchpath_destroy (searchpath, length);