]> 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:36:04 +0000 (16:36 +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 8bf81f5ad7f5fd22cf37fa56c1278f8129d6cd60..53453842a7145636b3471c02a6a1e603572f8b31 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 74c33014333ec3ed59bce1a30a3ae197fb3fbb59..61520789c1d819330f1813b4bd2cd2874326ccb0 100644 (file)
@@ -31,6 +31,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 fe89fdffa1b901645fdb3efd845749c004bf81e0..7252dd66d1ab6128ffa687d6d755b07e6647fe7f 100644 (file)
@@ -1,5 +1,5 @@
 # futimens.m4
-# serial 11
+# 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,
@@ -32,22 +32,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],