Index | Thread | Search

From:
Collin Funk <collin.funk1@gmail.com>
Subject:
ksh: use nanosecond resolution in the test builtin
To:
tech@openbsd.org
Date:
Sun, 23 Mar 2025 23:29:58 -0700

Download raw body.

Thread
Hi,

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

This caused a failure in the autoconf test suite, but that can easily be
fixed with a sleep.

Here is it implemented anyways:

Index: c_test.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_test.c,v
diff -u -p -u -p -r1.28 c_test.c
--- c_test.c	10 Jun 2023 07:24:21 -0000	1.28
+++ c_test.c	24 Mar 2025 06:25:09 -0000
@@ -327,7 +327,7 @@ test_eval(Test_env *te, Test_op op, cons
 			 */
 			return stat(opnd1, &b1) == 0 &&
 			    (((s2 = stat(opnd2, &b2)) == 0 &&
-			    b1.st_mtime > b2.st_mtime) || s2 < 0);
+			    timespeccmp(&b1.st_mtim, &b2.st_mtim, >)) || 0);
 		}
 	case TO_FILOT: /* -ot */
 		{
@@ -337,7 +337,7 @@ test_eval(Test_env *te, Test_op op, cons
 			 */
 			return stat(opnd2, &b2) == 0 &&
 			    (((s1 = stat(opnd1, &b1)) == 0 &&
-			    b1.st_mtime < b2.st_mtime) || s1 < 0);
+			    timespeccmp(&b1.st_mtim, &b2.st_mtim, <)) || 0);
 		}
 	case TO_FILEQ: /* -ef */
 		return stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 &&