dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Petr Skočík" <pskocik@gmail.com>
To: dash@vger.kernel.org
Subject: Greater resolution in test -nt / test -ot
Date: Thu, 22 Jun 2017 10:30:02 +0200	[thread overview]
Message-ID: <9903b02c-041f-38b6-e510-06b9f8744fbb@gmail.com> (raw)

Hi,

would you be willing to pull something like this?

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

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).

Best Regards,
Petr Skocik

                 reply	other threads:[~2017-06-22  8:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9903b02c-041f-38b6-e510-06b9f8744fbb@gmail.com \
    --to=pskocik@gmail.com \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).