]> Savannah Git Hosting - gnulib.git/commitdiff
utime-h: Modernize handling of 'struct utimbuf'.
authorBruno Haible <bruno@clisp.org>
Sat, 29 Apr 2017 23:26:05 +0000 (01:26 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 30 Apr 2017 08:30:58 +0000 (10:30 +0200)
* lib/utime.in.h: Include next <utime.h> if it exists.
(utimbuf): Define to _utimbuf on native Windows.
* m4/utime-h.m4 (gl_UTIME_H): Check for prerequisites of include_next.
Set UTIME_H on native Windows.
(gl_UTIME_MODULE_INDICATOR, gl_HEADER_UTIME_H_DEFAULTS): New macros.
* modules/utime-h (Depends-on): Add include_next.
(Makefile.am): Substitute also HAVE_UTIME_H, INCLUDE_NEXT,
PRAGMA_SYSTEM_HEADER, PRAGMA_COLUMNS, NEXT_UTIME_H.

* lib/utimens.c (utimbuf): Remove fallback definition.
* m4/utimens.m4 (gl_UTIMENS): Don't require
gl_CHECK_TYPE_STRUCT_UTIMBUF.
* m4/utimbuf.m4: Remove file.
* modules/utimens (Files): Remove m4/utimbuf.m4.

ChangeLog
lib/utime.in.h
lib/utimens.c
m4/utimbuf.m4 [deleted file]
m4/utime_h.m4
m4/utimens.m4
modules/utime-h
modules/utimens

index 8110195182df295f96ffaac2fc1aab39282bfd1a..702a2d7481a63929fa87851f93e99663d2b9e2d8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2017-04-29  Bruno Haible  <bruno@clisp.org>
+
+       utime-h: Modernize handling of 'struct utimbuf'.
+       * lib/utime.in.h: Include next <utime.h> if it exists.
+       (utimbuf): Define to _utimbuf on native Windows.
+       * m4/utime_h.m4 (gl_UTIME_H): Check for prerequisites of include_next.
+       Set UTIME_H on native Windows.
+       (gl_UTIME_MODULE_INDICATOR, gl_HEADER_UTIME_H_DEFAULTS): New macros.
+       * modules/utime-h (Depends-on): Add include_next.
+       (Makefile.am): Substitute also HAVE_UTIME_H, INCLUDE_NEXT,
+       PRAGMA_SYSTEM_HEADER, PRAGMA_COLUMNS, NEXT_UTIME_H.
+
+       * lib/utimens.c (utimbuf): Remove fallback definition.
+       * m4/utimens.m4 (gl_UTIMENS): Don't require
+       gl_CHECK_TYPE_STRUCT_UTIMBUF.
+       * m4/utimbuf.m4: Remove file.
+       * modules/utimens (Files): Remove m4/utimbuf.m4.
+
 2017-04-29  Bruno Haible  <bruno@clisp.org>
 
        Make use of module 'utime-h'.
index 0e3926a3eddc621bf79c3c4edc9ab0befd5788cc..26a1ceaca618364b677899b8646a1ca2b116d3ac 100644 (file)
@@ -1,4 +1,4 @@
-/* Substitute for <utime.h>
+/* Substitute for and wrapper around <utime.h>.
    Copyright (C) 2017 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.  */
 
+#ifndef _@GUARD_PREFIX@_UTIME_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_UTIME_H@
+# @INCLUDE_NEXT@ @NEXT_UTIME_H@
+#endif
+
 #ifndef _@GUARD_PREFIX@_UTIME_H
 #define _@GUARD_PREFIX@_UTIME_H
 
-#include <sys/utime.h>
+#if !@HAVE_UTIME_H@
+# include <sys/utime.h>
+#endif
 
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Define 'struct utimbuf' as an alias of 'struct _utimbuf'
+   (or possibly, if present, 'struct __utimbuf64').  */
+# define utimbuf _utimbuf
+
+#endif
+
+#endif /* _@GUARD_PREFIX@_UTIME_H */
 #endif /* _@GUARD_PREFIX@_UTIME_H */
index 5c6e4046f739560aff3c9cfdd9dde90ff4f1b9f3..3b4511933504d2c8c78720908151c854d32d4b60 100644 (file)
 #include "stat-time.h"
 #include "timespec.h"
 
-/* Some systems (even some that do have <utime.h>) don't declare this
-   structure anywhere.  */
-#ifndef HAVE_STRUCT_UTIMBUF
-struct utimbuf
-{
-  long actime;
-  long modtime;
-};
-#endif
-
 /* Avoid recursion with rpl_futimens or rpl_utimensat.  */
 #undef futimens
 #undef utimensat
diff --git a/m4/utimbuf.m4 b/m4/utimbuf.m4
deleted file mode 100644 (file)
index 1c42234..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-# serial 9
-
-# Copyright (C) 1998-2001, 2003-2004, 2007, 2009-2017 Free Software Foundation,
-# Inc.
-#
-# This file is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-dnl From Jim Meyering
-
-dnl Define HAVE_STRUCT_UTIMBUF if 'struct utimbuf' is declared --
-dnl usually in <utime.h>.
-dnl Some systems have utime.h but don't declare the struct anywhere.
-
-AC_DEFUN([gl_CHECK_TYPE_STRUCT_UTIMBUF],
-[
-  AC_CHECK_HEADERS_ONCE([sys/time.h utime.h])
-  AC_CACHE_CHECK([for struct utimbuf], [gl_cv_sys_struct_utimbuf],
-    [AC_COMPILE_IFELSE(
-       [AC_LANG_PROGRAM(
-          [[#if HAVE_SYS_TIME_H
-             #include <sys/time.h>
-            #endif
-            #include <time.h>
-            #ifdef HAVE_UTIME_H
-             #include <utime.h>
-            #endif
-          ]],
-          [[static struct utimbuf x; x.actime = x.modtime;]])],
-       [gl_cv_sys_struct_utimbuf=yes],
-       [gl_cv_sys_struct_utimbuf=no])])
-
-  if test $gl_cv_sys_struct_utimbuf = yes; then
-    AC_DEFINE([HAVE_STRUCT_UTIMBUF], [1],
-      [Define if struct utimbuf is declared -- usually in <utime.h>.
-       Some systems have utime.h but don't declare the struct anywhere. ])
-  fi
-])
index c29ae42d09a25e65059d01debd43d1f6da979c47..6b0ac5c2f9123cffe619ec3a953fe745e23e618c 100644 (file)
@@ -8,12 +8,43 @@ dnl From Bruno Haible.
 
 AC_DEFUN([gl_UTIME_H],
 [
-  UTIME_H=''
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([gl_UTIME_H_DEFAULTS])
   AC_CHECK_HEADERS_ONCE([utime.h])
+  gl_CHECK_NEXT_HEADERS([utime.h])
+
+  if test $ac_cv_header_utime_h = yes; then
+    HAVE_UTIME_H=1
+  else
+    HAVE_UTIME_H=0
+  fi
+  AC_SUBST([HAVE_UTIME_H])
+
+  UTIME_H=''
   if test $ac_cv_header_utime_h != yes; then
     dnl Provide a substitute <utime.h> file.
     UTIME_H=utime.h
+  else
+    case "$host_os" in
+      mingw*) dnl Need special handling of 'struct utimbuf'.
+        UTIME_H=utime.h
+        ;;
+    esac
   fi
   AC_SUBST([UTIME_H])
   AM_CONDITIONAL([GL_GENERATE_UTIME_H], [test -n "$UTIME_H"])
 ])
+
+AC_DEFUN([gl_UTIME_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_UTIME_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_UTIME_H_DEFAULTS],
+[
+  dnl Assume POSIX behavior unless another module says otherwise.
+])
index c58e93caaae822e276ded5345cedaad57db6e807..f3feab38da34f59a178280dfe2ff83d8bc4a510a 100644 (file)
@@ -3,14 +3,13 @@ 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.
 
-dnl serial 7
+dnl serial 8
 
 AC_DEFUN([gl_UTIMENS],
 [
   dnl Prerequisites of lib/utimens.c.
   AC_REQUIRE([gl_FUNC_UTIMES])
   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
-  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_UTIMBUF])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat lutimes])
 
index 6e32c501b27064c28e416e602b46a9df83068560..0e02d5b351416170492c33843b205b331b79cd85 100644 (file)
@@ -6,6 +6,7 @@ lib/utime.in.h
 m4/utime_h.m4
 
 Depends-on:
+include_next
 
 configure.ac:
 gl_UTIME_H
@@ -20,6 +21,11 @@ utime.h: utime.in.h $(top_builddir)/config.status
        $(AM_V_GEN)rm -f $@-t $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
          sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+             -e 's/@''HAVE_UTIME_H''@/$(HAVE_UTIME_H)/g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_UTIME_H''@|$(NEXT_UTIME_H)|g' \
              < $(srcdir)/utime.in.h; \
        } > $@-t && \
        mv $@-t $@
index b43872eb8f0d1e38b01ee5467a78a9aad7b0881e..c8167ced2b84b4b048063618dc13d7893464ca52 100644 (file)
@@ -4,7 +4,6 @@ Set file access and modification times.
 Files:
 lib/utimens.c
 lib/utimens.h
-m4/utimbuf.m4
 m4/utimens.m4
 m4/utimes.m4