bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patch] enhancement for "test -nt" to support nanosecond timestamps


From: Jim Meyering
Subject: Re: [patch] enhancement for "test -nt" to support nanosecond timestamps where available
Date: Sun, 14 Aug 2005 16:31:05 +0200

James Youngman <address@hidden> wrote:
> The attcached patch enhances "test" and "[" to take account of the
> nanoseconds part of the mtime when evaluating "test A -nt B" and "test
> A -ot B".

Thanks again.
I've just made this slightly different change:
(using TIMESPEC_NS and `long' rather than `unsigned long')

2005-08-14  James Youngman  <address@hidden>

        * src/test.c (age_of): Return the nanoseconds part of the timestamp,
        if available.
        (binary_operator) [-nt, -ot]: Use nanosecond values to break ties.

Index: src/test.c
===================================================================
RCS file: /fetish/cu/src/test.c,v
retrieving revision 1.120
retrieving revision 1.122
diff -u -p -r1.120 -r1.122
--- src/test.c  30 May 2005 07:34:23 -0000      1.120
+++ src/test.c  14 Aug 2005 14:22:00 -0000      1.122
@@ -160,14 +160,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 +324,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], &lt);
-             re = age_of (argv[op + 1], &rt);
-             return le > re || (le && lt > rt);
+             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);
            }
          break;
 
@@ -349,13 +359,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], &lt);
-             re = age_of (argv[op + 1], &rt);
-             return le < re || (re && lt < rt);
+             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);
            }
          break;
        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]