diff options
author | Martijn Dekker <martijn@inlv.org> | 2018-03-07 17:32:29 +0000 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2020-03-28 21:42:54 +0000 |
commit | e86e3a7edc8934dc6a9ecd4bb360d19672f65ccf (patch) | |
tree | bd871980bc10da065166f581f3149b0ab6b8989b | |
parent | 3f6667917c6cc2c90803e1a3e865f2c3b8b1bbf3 (diff) | |
download | klibc-e86e3a7edc8934dc6a9ecd4bb360d19672f65ccf.tar.gz |
[klibc] dash: builtin: Greater resolution in test -nt / test -ot
[ dash commit fc914153d433b063b9ed11f3ace668c5c866f379 ]
Op 07-03-18 om 15:46 schreef Martijn Dekker:
> 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.
Here's an attempt to make that happen. See attached.
- M.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | usr/dash/bltin/test.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/usr/dash/bltin/test.c b/usr/dash/bltin/test.c index 58c05fecfba6f..d1458df34d26c 100644 --- a/usr/dash/bltin/test.c +++ b/usr/dash/bltin/test.c @@ -476,9 +476,17 @@ newerf (const char *f1, const char *f2) { struct stat b1, b2; +#ifdef HAVE_ST_MTIM + return (stat (f1, &b1) == 0 && + stat (f2, &b2) == 0 && + ( 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 ))) + ); +#else return (stat (f1, &b1) == 0 && stat (f2, &b2) == 0 && b1.st_mtime > b2.st_mtime); +#endif } static int @@ -486,9 +494,17 @@ olderf (const char *f1, const char *f2) { struct stat b1, b2; +#ifdef HAVE_ST_MTIM + return (stat (f1, &b1) == 0 && + stat (f2, &b2) == 0 && + (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 ))) + ); +#else return (stat (f1, &b1) == 0 && stat (f2, &b2) == 0 && b1.st_mtime < b2.st_mtime); +#endif } static int |