summaryrefslogtreecommitdiff
path: root/src/test.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-09-16 07:42:56 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-09-16 07:42:56 +0000
commit3ecd35f56fbb7f9b3f43cd12f862336acf7dca56 (patch)
treea5f29d39cefde93a9fb6a299114652274b5d8ed8 /src/test.c
parentb95a4ed1ce0b61a2d76307b10b82a3eb89932692 (diff)
downloadcoreutils-3ecd35f56fbb7f9b3f43cd12f862336acf7dca56.tar.xz
Include stat-time.h, and use its functions instead of the obsolete
TIMESPEC_NS macro. (get_mtime): Renamed from age_of. All uses changed.
Diffstat (limited to 'src/test.c')
-rw-r--r--src/test.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/src/test.c b/src/test.c
index 3263cee0a..89ff95dbd 100644
--- a/src/test.c
+++ b/src/test.c
@@ -45,6 +45,7 @@
#include "euidaccess.h"
#include "inttostr.h"
#include "quote.h"
+#include "stat-time.h"
#include "strnumcmp.h"
#if HAVE_SYS_PARAM_H
@@ -159,20 +160,19 @@ find_int (char const *string)
test_syntax_error (_("invalid integer %s\n"), quote (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.
+/* Find the modification time of FILE, and stuff it into *MTIME.
Return true if successful. */
static bool
-age_of (char const *filename, time_t *age, long *ns)
+get_mtime (char const *filename, struct timespec *mtime)
{
struct stat finfo;
bool ok = (stat (filename, &finfo) == 0);
+#ifdef lint
+ static struct timespec const zero;
+ *mtime = zero;
+#endif
if (ok)
- {
- *age = finfo.st_mtime;
- *ns = TIMESPEC_NS (finfo.st_mtim);
- }
+ *mtime = get_stat_mtime (&finfo);
return ok;
}
@@ -322,20 +322,14 @@ binary_operator (bool l_is_l)
if (argv[op][2] == 't' && !argv[op][3])
{
/* 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);
+ struct timespec lt, rt;
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], &lt, &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);
+ le = get_mtime (argv[op - 1], &lt);
+ re = get_mtime (argv[op + 1], &rt);
+ return le && (!re || timespec_cmp (lt, rt) > 0);
}
break;
@@ -357,20 +351,14 @@ binary_operator (bool l_is_l)
if ('t' == argv[op][2] && '\000' == argv[op][3])
{
/* 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);
+ struct timespec lt, rt;
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], &lt, &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);
+ le = get_mtime (argv[op - 1], &lt);
+ re = get_mtime (argv[op + 1], &rt);
+ return re && (!le || timespec_cmp (lt, rt) < 0);
}
break;
}