]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: touch: prefer timespec_cmp
authorCollin Funk <collin.funk1@gmail.com>
Thu, 9 Apr 2026 05:34:13 +0000 (22:34 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Thu, 9 Apr 2026 05:34:13 +0000 (22:34 -0700)
* src/touch.c (main): Use timespec_cmp instead of comparing each member
of the timespec.

src/touch.c

index 3d369ee427dc0c5cb82f93ad0442313b5e003b19..ad1ea5e0ef9d04d0dbeebce8914a2f8571ca3410 100644 (file)
@@ -385,8 +385,7 @@ main (int argc, char **argv)
              it were absent; this lets "touch" succeed more often in
              the presence of restrictive permissions.  */
           if (change_times == (CH_ATIME | CH_MTIME)
-              && newtime[0].tv_sec == now.tv_sec
-              && newtime[0].tv_nsec == now.tv_nsec)
+              && timespec_cmp (newtime[0], now) == 0)
             {
               /* Check that it really was "-d now", and not a timestamp
                  that just happens to be the current time.  */
@@ -394,8 +393,7 @@ main (int argc, char **argv)
               notnow.tv_sec = now.tv_sec ^ 1;
               notnow.tv_nsec = now.tv_nsec;
               notnow1 = date_relative (flex_date, notnow);
-              if (notnow1.tv_sec == notnow.tv_sec
-                  && notnow1.tv_nsec == notnow.tv_nsec)
+              if (timespec_cmp (notnow1, notnow) == 0)
                 date_set = false;
             }
         }