diff options
author | Jim Meyering <jim@meyering.net> | 2005-08-14 14:17:48 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2005-08-14 14:17:48 +0000 |
commit | c41d32149ac085c14461a68200c7bfd141320e7d (patch) | |
tree | 9f7eaa753df80a3129a37f4f943769f2cd88e007 /src | |
parent | 9d9ca33394c3544dffa73685b4236e2ee300ec4d (diff) | |
download | coreutils-c41d32149ac085c14461a68200c7bfd141320e7d.tar.xz |
Include "timespec.h".
(age_of): Return the nanoseconds part of the timestamp, if available.
(binary_operator) [-nt, -ot]: Use nanosecond values to break ties.
Diffstat (limited to 'src')
-rw-r--r-- | src/test.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/test.c b/src/test.c index 659b17c3b..27883640c 100644 --- a/src/test.c +++ b/src/test.c @@ -46,6 +46,7 @@ #include "inttostr.h" #include "quote.h" #include "strnumcmp.h" +#include "timespec.h" #if HAVE_SYS_PARAM_H # include <sys/param.h> @@ -160,14 +161,19 @@ find_int (char const *string) } /* Find the modification time of FILE, and stuff it into *AGE. + If the timestamp has a nonoseconds part, stuff that into *NS; + otherwise stuff zero into *NS. Return true if successful. */ static bool -age_of (char const *filename, time_t *age) +age_of (char const *filename, time_t *age, long *ns) { struct stat finfo; bool ok = (stat (filename, &finfo) == 0); if (ok) - *age = finfo.st_mtime; + { + *age = finfo.st_mtime; + *ns = TIMESPEC_NS (finfo.st_mtim); + } return ok; } @@ -319,13 +325,18 @@ binary_operator (bool l_is_l) /* nt - newer than */ time_t lt IF_LINT (= 0); time_t rt IF_LINT (= 0); + long l_ns IF_LINT (= 0); + long r_ns IF_LINT (= 0); bool le, re; pos += 3; if (l_is_l | r_is_l) test_syntax_error (_("-nt does not accept -l\n"), NULL); - le = age_of (argv[op - 1], <); - re = age_of (argv[op + 1], &rt); - return le > re || (le && lt > rt); + le = age_of (argv[op - 1], <, &l_ns); + re = age_of (argv[op + 1], &rt, &r_ns); + if (le && re && (rt == lt)) + return l_ns > r_ns; + else + return le > re || (le && lt > rt); } break; @@ -349,13 +360,18 @@ binary_operator (bool l_is_l) /* ot - older than */ time_t lt IF_LINT (= 0); time_t rt IF_LINT (= 0); + long l_ns IF_LINT (= 0); + long r_ns IF_LINT (= 0); bool le, re; pos += 3; if (l_is_l | r_is_l) test_syntax_error (_("-ot does not accept -l\n"), NULL); - le = age_of (argv[op - 1], <); - re = age_of (argv[op + 1], &rt); - return le < re || (re && lt < rt); + le = age_of (argv[op - 1], <, &l_ns); + re = age_of (argv[op + 1], &rt, &r_ns); + if (le && re && (lt == rt)) + return l_ns < r_ns; + else + return le < re || (re && lt < rt); } break; } |