tech-userlevel archive

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

test(1)/find(1) time comparison with timespec



Use timespec (st_mtimespec) instead of time_t (st_mtime) in time(1)'s -nt
(newer than) / -ot (older than) and find(1)'s -newer.

Question is, if these changes will surprise someone somewhere?
Index: bin/test/test.c
===================================================================
RCS file: /cvsroot/src/bin/test/test.c,v
retrieving revision 1.39
diff -u -r1.39 test.c
--- bin/test/test.c     15 Mar 2012 02:02:21 -0000      1.39
+++ bin/test/test.c     23 Apr 2013 13:28:26 -0000
@@ -694,7 +694,7 @@
 
        return (stat(f1, &b1) == 0 &&
                stat(f2, &b2) == 0 &&
-               b1.st_mtime > b2.st_mtime);
+               timespeccmp(&b1.st_mtimespec, &b2.st_mtimespec, >));
 }
 
 static int
@@ -704,7 +704,7 @@
 
        return (stat(f1, &b1) == 0 &&
                stat(f2, &b2) == 0 &&
-               b1.st_mtime < b2.st_mtime);
+               timespeccmp(&b1.st_mtimespec, &b2.st_mtimespec, <));
 }
 
 static int
Index: usr.bin/find/find.h
===================================================================
RCS file: /cvsroot/src/usr.bin/find/find.h,v
retrieving revision 1.24
diff -u -r1.24 find.h
--- usr.bin/find/find.h 6 Feb 2007 13:25:01 -0000       1.24
+++ usr.bin/find/find.h 23 Apr 2013 13:28:36 -0000
@@ -35,6 +35,7 @@
  */
 
 #include <regex.h>
+#include <time.h>
 
 /* node type */
 enum ntype {
@@ -71,6 +72,7 @@
                nlink_t _l_data;                /* link count */
                off_t _o_data;                  /* file size */
                time_t _t_data;                 /* time value */
+               struct timespec _ts_data;       /* time value */
                uid_t _u_data;                  /* uid */
                short _mt_data;                 /* mount flags */
                struct _plandata *_p_data[2];   /* PLAN trees */
@@ -106,6 +108,7 @@
 #define        o_data          p_un._o_data
 #define        p_data          p_un._p_data
 #define        t_data          p_un._t_data
+#define        ts_data         p_un._ts_data
 #define        u_data          p_un._u_data
 #define        e_argv          p_un.ex._e_argv
 #define        e_orig          p_un.ex._e_orig
Index: usr.bin/find/function.c
===================================================================
RCS file: /cvsroot/src/usr.bin/find/function.c,v
retrieving revision 1.71
diff -u -r1.71 function.c
--- usr.bin/find/function.c     26 Aug 2012 14:26:37 -0000      1.71
+++ usr.bin/find/function.c     23 Apr 2013 13:28:36 -0000
@@ -218,7 +218,7 @@
 f_anewer(PLAN *plan, FTSENT *entry)
 {
 
-       return (entry->fts_statp->st_atime > plan->t_data);
+       return timespeccmp(&entry->fts_statp->st_atimespec, &plan->ts_data, >);
 }
 
 PLAN *
@@ -234,7 +234,7 @@
        if (stat(filename, &sb))
                err(1, "%s", filename);
        new = palloc(N_ANEWER, f_anewer);
-       new->t_data = sb.st_atime;
+       new->ts_data = sb.st_atimespec;
        return (new);
 }
 
@@ -265,6 +265,7 @@
        TIME_CORRECT(new, N_ATIME);
        return (new);
 }
+
 /*
  * -cmin n functions --
  *
@@ -304,7 +305,7 @@
 f_cnewer(PLAN *plan, FTSENT *entry)
 {
 
-       return (entry->fts_statp->st_ctime > plan->t_data);
+       return timespeccmp(&entry->fts_statp->st_ctimespec, &plan->ts_data, >);
 }
 
 PLAN *
@@ -320,7 +321,7 @@
        if (stat(filename, &sb))
                err(1, "%s", filename);
        new = palloc(N_CNEWER, f_cnewer);
-       new->t_data = sb.st_ctime;
+       new->ts_data = sb.st_ctimespec;
        return (new);
 }
 
@@ -1212,6 +1213,7 @@
        new->min_data = atoi(arg);
        return (new);
 }
+
 /*
  * -mmin n functions --
  *
@@ -1239,6 +1241,7 @@
        TIME_CORRECT(new, N_MMIN);
        return (new);
 }
+
 /*
  * -mtime n functions --
  *
@@ -1327,7 +1330,7 @@
 f_newer(PLAN *plan, FTSENT *entry)
 {
 
-       return (entry->fts_statp->st_mtime > plan->t_data);
+       return timespeccmp(&entry->fts_statp->st_mtimespec, &plan->ts_data, >);
 }
 
 PLAN *
@@ -1343,7 +1346,7 @@
        if (stat(filename, &sb))
                err(1, "%s", filename);
        new = palloc(N_NEWER, f_newer);
-       new->t_data = sb.st_mtime;
+       new->ts_data = sb.st_mtimespec;
        return (new);
 }
 


Home | Main Index | Thread Index | Old Index