From 127cc8158810518f7abb27777b649468d91fda8b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Apr 2017 01:26:05 +0200 Subject: [PATCH] utime-h: Modernize handling of 'struct utimbuf'. * lib/utime.in.h: Include next 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 | 18 ++++++++++++++++++ lib/utime.in.h | 27 +++++++++++++++++++++++++-- lib/utimens.c | 10 ---------- m4/utimbuf.m4 | 39 --------------------------------------- m4/utime_h.m4 | 33 ++++++++++++++++++++++++++++++++- m4/utimens.m4 | 3 +-- modules/utime-h | 6 ++++++ modules/utimens | 1 - 8 files changed, 82 insertions(+), 55 deletions(-) delete mode 100644 m4/utimbuf.m4 diff --git a/ChangeLog b/ChangeLog index 8110195182..702a2d7481 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2017-04-29 Bruno Haible + + utime-h: Modernize handling of 'struct utimbuf'. + * lib/utime.in.h: Include next 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 Make use of module 'utime-h'. diff --git a/lib/utime.in.h b/lib/utime.in.h index 0e3926a3ed..26a1ceaca6 100644 --- a/lib/utime.in.h +++ b/lib/utime.in.h @@ -1,4 +1,4 @@ -/* Substitute for +/* Substitute for and wrapper around . Copyright (C) 2017 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -14,9 +14,32 @@ You should have received a copy of the GNU General Public License along with this program; if not, see . */ +#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 +#if !@HAVE_UTIME_H@ +# include +#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 */ diff --git a/lib/utimens.c b/lib/utimens.c index 5c6e4046f7..3b45119335 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -35,16 +35,6 @@ #include "stat-time.h" #include "timespec.h" -/* Some systems (even some that do have ) 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 index 1c42234959..0000000000 --- a/m4/utimbuf.m4 +++ /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 . -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 - #endif - #include - #ifdef HAVE_UTIME_H - #include - #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 . - Some systems have utime.h but don't declare the struct anywhere. ]) - fi -]) diff --git a/m4/utime_h.m4 b/m4/utime_h.m4 index c29ae42d09..6b0ac5c2f9 100644 --- a/m4/utime_h.m4 +++ b/m4/utime_h.m4 @@ -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 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. +]) diff --git a/m4/utimens.m4 b/m4/utimens.m4 index c58e93caaa..f3feab38da 100644 --- a/m4/utimens.m4 +++ b/m4/utimens.m4 @@ -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]) diff --git a/modules/utime-h b/modules/utime-h index 6e32c501b2..0e02d5b351 100644 --- a/modules/utime-h +++ b/modules/utime-h @@ -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 $@ diff --git a/modules/utimens b/modules/utimens index b43872eb8f..c8167ced2b 100644 --- a/modules/utimens +++ b/modules/utimens @@ -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 -- 2.39.5