On this platform, <sys/time.h> declares utimens and lutimens and the
C library defines them, so we needn’t (and shouldn’t).
Problem reported privately by Thomas Klausner.
* lib/utimens.c (utimens) [HAVE_UTIMENS]: Don’t define.
(lutimens) [HAVE_LUTIMENS]: Don’t define.
* lib/utimens.h [HAVE_UTIMENS || HAVE_LUTIMENS]:
Include <sys/time.h>, for NetBSD’s declaration of utimens and lutimens.
(utimens) [HAVE_UTIMENS]: Don’t declare.
(lutimens) [HAVE_LUTIMENS]: Don’t declare.
* m4/utimens.m4 (gl_UTIMENS): Check for utimens, lutimens.
---
 ChangeLog     | 14 ++++++++++++++
 lib/utimens.c |  4 ++++
 lib/utimens.h |  8 ++++++++
 m4/utimens.m4 |  3 ++-
 4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 9ba5d0a184..1270ac58c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-09-16  Paul Eggert  <egg...@cs.ucla.edu>
+
+       utimens: port to NetBSD-10.99.12/amd64
+       On this platform, <sys/time.h> declares utimens and lutimens and the
+       C library defines them, so we needn’t (and shouldn’t).
+       Problem reported privately by Thomas Klausner.
+       * lib/utimens.c (utimens) [HAVE_UTIMENS]: Don’t define.
+       (lutimens) [HAVE_LUTIMENS]: Don’t define.
+       * lib/utimens.h [HAVE_UTIMENS || HAVE_LUTIMENS]:
+       Include <sys/time.h>, for NetBSD’s declaration of utimens and lutimens.
+       (utimens) [HAVE_UTIMENS]: Don’t declare.
+       (lutimens) [HAVE_LUTIMENS]: Don’t declare.
+       * m4/utimens.m4 (gl_UTIMENS): Check for utimens, lutimens.
+
 2024-09-16  Bruno Haible  <br...@clisp.org>
 
        stdlib: Fix compilation error with Sun C++.
diff --git a/lib/utimens.c b/lib/utimens.c
index 6b9f62a53c..cd86a44ea7 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -516,6 +516,7 @@ fdutimens (int fd, char const *file, struct timespec const 
timespec[2])
   }
 }
 
+#if !HAVE_UTIMENS
 /* Set the access and modification timestamps of FILE to be
    TIMESPEC[0] and TIMESPEC[1], respectively.  */
 int
@@ -523,7 +524,9 @@ utimens (char const *file, struct timespec const 
timespec[2])
 {
   return fdutimens (-1, file, timespec);
 }
+#endif
 
+#if !HAVE_LUTIMENS
 /* Set the access and modification timestamps of FILE to be
    TIMESPEC[0] and TIMESPEC[1], respectively, without dereferencing
    symlinks.  Fail with ENOSYS if the platform does not support
@@ -646,3 +649,4 @@ lutimens (char const *file, struct timespec const 
timespec[2])
   errno = ENOSYS;
   return -1;
 }
+#endif
diff --git a/lib/utimens.h b/lib/utimens.h
index b20d4f4f7e..e85477b849 100644
--- a/lib/utimens.h
+++ b/lib/utimens.h
@@ -24,13 +24,21 @@
 
 #include <time.h>
 
+#if HAVE_UTIMENS || HAVE_LUTIMENS
+# include <sys/time.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 int fdutimens (int, char const *, struct timespec const [2]);
+#if !HAVE_UTIMENS
 int utimens (char const *, struct timespec const [2]);
+#endif
+#if !HAVE_LUTIMENS
 int lutimens (char const *, struct timespec const [2]);
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/m4/utimens.m4 b/m4/utimens.m4
index 9996e3ef33..b8200deaa2 100644
--- a/m4/utimens.m4
+++ b/m4/utimens.m4
@@ -1,5 +1,5 @@
 # utimens.m4
-# serial 16
+# serial 17
 dnl Copyright (C) 2003-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -16,6 +16,7 @@ AC_DEFUN([gl_UTIMENS],
   gl_CHECK_FUNCS_ANDROID([lutimes], [[#include <sys/time.h>]])
   gl_CHECK_FUNCS_ANDROID([futimens], [[#include <sys/stat.h>]])
   gl_CHECK_FUNCS_ANDROID([utimensat], [[#include <sys/stat.h>]])
+  AC_CHECK_FUNCS_ONCE([utimens lutimens])
 
   if test $ac_cv_func_futimens = no && test $ac_cv_func_futimesat = yes; then
     dnl FreeBSD 8.0-rc2 mishandles futimesat(fd,NULL,time).  It is not
-- 
2.43.0


Reply via email to