[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
modernize handling of 'struct utimbuf'
From: |
Bruno Haible |
Subject: |
modernize handling of 'struct utimbuf' |
Date: |
Sun, 30 Apr 2017 19:32:07 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-75-generic; KDE/5.18.0; x86_64; ; ) |
On Unix systems, there is no problem any more nowadays with 'struct utimbuf':
A web search for "checking for struct utimbuf... no" does not find any
relevant hits in the last 11 years.
On the other hand, there is a problem on native Windows (both mingw and MSVC):
The header file defines 'struct _utimbuf' in this case.
This patch removes the old gl_CHECK_TYPE_STRUCT_UTIMBUF macro and instead
adds the proper support for native Windows.
2017-04-29 Bruno Haible <address@hidden>
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.
diff --git a/lib/utime.in.h b/lib/utime.in.h
index 0e3926a..26a1cea 100644
--- a/lib/utime.in.h
+++ b/lib/utime.in.h
@@ -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
@@ -15,8 +15,31 @@
along with this program; if not, see <http://www.gnu.org/licenses/>. */
#ifndef address@hidden@_UTIME_H
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+/* The include_next requires a split double-inclusion guard. */
+#if @HAVE_UTIME_H@
+# @INCLUDE_NEXT@ @NEXT_UTIME_H@
+#endif
+
+#ifndef address@hidden@_UTIME_H
#define address@hidden@_UTIME_H
-#include <sys/utime.h>
+#if address@hidden@
+# 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 /* address@hidden@_UTIME_H */
#endif /* address@hidden@_UTIME_H */
diff --git a/lib/utimens.c b/lib/utimens.c
index 5c6e404..3b45119 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 <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
index 1c42234..0000000
--- 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 <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
-])
diff --git a/m4/utime_h.m4 b/m4/utime_h.m4
index c29ae42..6b0ac5c 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 <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.
+])
diff --git a/m4/utimens.m4 b/m4/utimens.m4
index c58e93c..f3feab3 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 6e32c50..0e02d5b 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 address@hidden $@ && \
{ 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; \
} > address@hidden && \
mv address@hidden $@
diff --git a/modules/utimens b/modules/utimens
index b43872e..c8167ce 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- modernize handling of 'struct utimbuf',
Bruno Haible <=