Index | Thread | Search

From:
Collin Funk <collin.funk1@gmail.com>
Subject:
test: use nanosecond resolution for '-ot' and '-nt'
To:
tech@openbsd.org
Date:
Sun, 23 Mar 2025 23:41:22 -0700

Download raw body.

Thread
Collin Funk <collin.funk1@gmail.com> writes:

> The ksh test builtin does not support nanosecond resolution which is
> possible with the timespec structure.

Likewise for the actual test program.

Index: bin/test/test.c
===================================================================
RCS file: /cvs/src/bin/test/test.c,v
diff -u -p -u -p -r1.22 test.c
--- bin/test/test.c	15 Aug 2024 06:27:24 -0000	1.22
+++ bin/test/test.c	24 Mar 2025 06:37:43 -0000
@@ -546,7 +546,7 @@ newerf(const char *f1, const char *f2)
 
 	return (stat(f1, &b1) == 0 &&
 	    stat(f2, &b2) == 0 &&
-	    b1.st_mtime > b2.st_mtime);
+	    timespeccmp(&b1.st_mtim, &b2.st_mtim, >));
 }
 
 static int
@@ -556,7 +556,7 @@ olderf(const char *f1, const char *f2)
 
 	return (stat(f1, &b1) == 0 &&
 	    stat(f2, &b2) == 0 &&
-	    b1.st_mtime < b2.st_mtime);
+	    timespeccmp(&b1.st_mtim, &b2.st_mtim, <));
 }