]> Savannah Git Hosting - gnulib.git/commitdiff
futimens: Work around a GNU/Hurd bug.
authorCollin Funk <collin.funk1@gmail.com>
Wed, 19 Mar 2025 04:50:00 +0000 (21:50 -0700)
committerBruno Haible <bruno@clisp.org>
Tue, 1 Apr 2025 14:54:13 +0000 (16:54 +0200)
* m4/futimens.m4 (gl_FUNC_FUTIMENS): Check if futimens validates the
tv_nsec values of the timespec argument. Set bits in a return value
instead of exiting early.
* doc/posix-functions/futimens.texi (futimens): Mention the GNU/Hurd
bug. Mention the same bug occurs on NetBSD 10.

ChangeLog
doc/posix-functions/futimens.texi
m4/futimens.m4

index e22981469faacd51d1f9fc8c90e671178501e1a3..44a186dea19faccc0b39db75c58c9e0fa6c00cf1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-03-18  Collin Funk  <collin.funk1@gmail.com>
+
+       futimens: Work around a GNU/Hurd bug.
+       * m4/futimens.m4 (gl_FUNC_FUTIMENS): Check if futimens validates the
+       tv_nsec values of the timespec argument. Set bits in a return value
+       instead of exiting early.
+       * doc/posix-functions/futimens.texi (futimens): Mention the GNU/Hurd
+       bug. Mention the same bug occurs on NetBSD 10.
+
 2025-03-17  Collin Funk  <collin.funk1@gmail.com>
 
        utimensat: Work around a GNU/Hurd bug.
index 0926616ff59f605643adcfe3bce0f768abc4f7fe..5de37fc103fbb8ddf29b11895ccb29717b3900bb 100644 (file)
@@ -30,6 +30,11 @@ Linux kernel 2.6.32, macOS 14, NetBSD 10.0, Solaris 11.1.
 Passing @code{AT_FDCWD} as the fd argument does not properly fail with
 @code{EBADF} on some systems:
 glibc 2.11, musl libc, Solaris 11.
+@item
+Out-of-range values of @code{tv_nsec} do not lead to a failure on some
+platforms:
+@c https://sourceware.org/bugzilla/show_bug.cgi?id=32803
+NetBSD 10.0, GNU/Hurd.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index b5f22605f49048a13905f90d24f92e65083d5cc1..4849f69a4610d6ed24003e4c5cb97c30877fb9ce 100644 (file)
@@ -1,6 +1,6 @@
 # futimens.m4
-# serial 11
-dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
+# serial 12
+dnl Copyright (C) 2009-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -31,22 +31,45 @@ AC_DEFUN([gl_FUNC_FUTIMENS],
 ]GL_MDA_DEFINES],
      [[struct timespec ts[2];
       int fd = creat ("conftest.file", 0600);
+      int result = 0;
       struct stat st;
-      if (fd < 0) return 1;
+      if (fd < 0)
+        return 1;
       ts[0].tv_sec = 1;
       ts[0].tv_nsec = UTIME_OMIT;
       ts[1].tv_sec = 1;
       ts[1].tv_nsec = UTIME_NOW;
       errno = 0;
-      if (futimens (AT_FDCWD, NULL) == 0) return 2;
-      if (errno != EBADF) return 3;
-      if (futimens (fd, ts)) return 4;
+      if (futimens (AT_FDCWD, NULL) == 0 || errno != EBADF)
+        result |= 2;
+      if (futimens (fd, ts))
+        result |= 4;
       sleep (1);
       ts[0].tv_nsec = UTIME_NOW;
       ts[1].tv_nsec = UTIME_OMIT;
-      if (futimens (fd, ts)) return 5;
-      if (fstat (fd, &st)) return 6;
-      if (st.st_ctime < st.st_atime) return 7;
+      if (futimens (fd, ts))
+        result |= 8;
+      if (fstat (fd, &st))
+        result |= 16;
+      if (st.st_ctime < st.st_atime)
+        result |= 32;
+      enum
+      {
+        BILLION = 1000 * 1000 * 1000,
+        /* Bogus positive and negative tv_nsec values closest to valid
+           range, but without colliding with UTIME_NOW or UTIME_OMIT.  */
+        UTIME_BOGUS_POS = BILLION + ((UTIME_NOW == BILLION || UTIME_OMIT == BILLION)
+                                     ? (1 + (UTIME_NOW == BILLION + 1)
+                                        + (UTIME_OMIT == BILLION + 1))
+                                     : 0)
+      };
+      ts[0].tv_sec = 1;
+      ts[0].tv_nsec = UTIME_BOGUS_POS;
+      ts[1].tv_sec = 1;
+      ts[1].tv_nsec = 0;
+      if (futimens (fd, ts) == 0)
+        result |= 64;
+      return result;
       ]])],
          [gl_cv_func_futimens_works=yes],
          [gl_cv_func_futimens_works=no],