diff mbox

Greater resolution in test -nt / test -ot

Message ID dd66399f-c702-21b6-b3a3-69235b78a9f6@inlv.org (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show

Commit Message

Martijn Dekker March 7, 2018, 3:46 p.m. UTC
Op 06-03-18 om 09:19 schreef Herbert Xu:
> On Thu, Jun 22, 2017 at 10:30:02AM +0200, Petr Skočík wrote:
>> would you be willing to pull something like this?
[...]
>> I could use greater resolution in `test -nt` / `test -ot`, and st_mtim
>> field is standardized under POSIX.1-2008 (or so stat(2) says).
> 
> Sure.  But your patch is corrupted.

Fixed patch attached.

But I wouldn't apply it as is. My system does not have st_mtim. So I
think it needs a configure test and a fallback to the old method.

- M.
diff mbox

Patch

diff --git a/src/bltin/test.c b/src/bltin/test.c
index 58c05fe..7ea02f2 100644
--- a/src/bltin/test.c
+++ b/src/bltin/test.c
@@ -478,7 +478,9 @@  newerf (const char *f1, const char *f2)
 
 	return (stat (f1, &b1) == 0 &&
 		stat (f2, &b2) == 0 &&
-		b1.st_mtime > b2.st_mtime);
+		( b1.st_mtim.tv_sec > b2.st_mtim.tv_sec ||
+		 (b1.st_mtim.tv_sec == b2.st_mtim.tv_sec && (b1.st_mtim.tv_nsec > b2.st_mtim.tv_nsec )))
+	);
 }
 
 static int
@@ -488,7 +490,9 @@  olderf (const char *f1, const char *f2)
 
 	return (stat (f1, &b1) == 0 &&
 		stat (f2, &b2) == 0 &&
-		b1.st_mtime < b2.st_mtime);
+		(b1.st_mtim.tv_sec < b2.st_mtim.tv_sec ||
+		 (b1.st_mtim.tv_sec == b2.st_mtim.tv_sec && (b1.st_mtim.tv_nsec < b2.st_mtim.tv_nsec )))
+	);
 }
 
 static int