changeset 12533:57ab00b8ee20

sys_times, sys_utsname: use include_next Another step towards being able to make GL_LINK_WARNING useful. * m4/sys_times_h.m4 (gl_SYS_TIMES_H): Support wrapping an existing header. (gl_SYS_TIMES_H_DEFAULTS): Add another variable. * m4/sys_utsname_h.m4 (gl_SYS_UTSNAME_H) (gl_SYS_UTSNAME_H_DEFAULTS): Likewise. * modules/sys_times (Depends-on): Add include_next. (Makefile.am): Substitute additional values. * modules/sys_utsname (Depends-on, Makefile.am): Likewise. * lib/sys_times.in.h (includes): Include native header, if available. * lib/sys_utsname.in.h (includes): Likewise. * tests/test-sys_times.c (main): Enhance test. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Wed, 30 Dec 2009 09:47:55 -0700
parents 1030f222bca1
children df55cbe78453
files ChangeLog lib/sys_times.in.h lib/sys_utsname.in.h m4/sys_times_h.m4 m4/sys_utsname_h.m4 modules/sys_times modules/sys_utsname tests/test-sys_times.c
diffstat 8 files changed, 100 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2009-12-31  Eric Blake  <ebb9@byu.net>
 
+	sys_times, sys_utsname: use include_next
+	* m4/sys_times_h.m4 (gl_SYS_TIMES_H): Support wrapping an existing
+	header.
+	(gl_SYS_TIMES_H_DEFAULTS): Add another variable.
+	* m4/sys_utsname_h.m4 (gl_SYS_UTSNAME_H)
+	(gl_SYS_UTSNAME_H_DEFAULTS): Likewise.
+	* modules/sys_times (Depends-on): Add include_next.
+	(Makefile.am): Substitute additional values.
+	* modules/sys_utsname (Depends-on, Makefile.am): Likewise.
+	* lib/sys_times.in.h (includes): Include native header, if
+	available.
+	* lib/sys_utsname.in.h (includes): Likewise.
+	* tests/test-sys_times.c (main): Enhance test.
+
 	fdutimensat: revert prior patch
 	* modules/fdutimensat (Depends-on): Re-add inline; it is needed by
 	utimens.h.
--- a/lib/sys_times.in.h
+++ b/lib/sys_times.in.h
@@ -21,6 +21,15 @@
    is missing.  */
 
 #ifndef _GL_SYS_TIMES_H
+
+# if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+# endif
+
+# if @HAVE_SYS_TIMES_H@
+#  @INCLUDE_NEXT@ @NEXT_SYS_TIMES_H@
+# endif
+
 # define _GL_SYS_TIMES_H
 
 /* Get clock_t. */
@@ -34,6 +43,7 @@
 extern "C" {
 # endif
 
+# if !@HAVE_STRUCT_TMS@
   /* Structure describing CPU time used by a process and its children.  */
   struct tms
   {
@@ -43,9 +53,12 @@
     clock_t tms_cutime;         /* User CPU time of dead children.  */
     clock_t tms_cstime;         /* System CPU time of dead children.  */
   };
+# endif
 
 # if @GNULIB_TIMES@
+#  if !@HAVE_TIMES@
   extern clock_t times (struct tms *buffer) _GL_ARG_NONNULL ((1));
+#  endif
 # elif defined GNULIB_POSIXCHECK
 #  undef times
 #  define times(s)                                              \
--- a/lib/sys_utsname.in.h
+++ b/lib/sys_utsname.in.h
@@ -16,6 +16,15 @@
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #ifndef _GL_SYS_UTSNAME_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+
+#if @HAVE_SYS_UTSNAME_H@
+# @INCLUDE_NEXT@ @NEXT_SYS_UTSNAME_H@
+#endif
+
 #define _GL_SYS_UTSNAME_H
 
 /* The definition of GL_LINK_WARNING is copied here.  */
@@ -27,25 +36,25 @@
 extern "C" {
 #endif
 
-
+#if !@HAVE_STRUCT_UTSNAME@
 /* Length of the entries in 'struct utsname' is 256.  */
-#define _UTSNAME_LENGTH 256
+# define _UTSNAME_LENGTH 256
 
-#ifndef _UTSNAME_NODENAME_LENGTH
-# define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH
-#endif
-#ifndef _UTSNAME_SYSNAME_LENGTH
-# define _UTSNAME_SYSNAME_LENGTH _UTSNAME_LENGTH
-#endif
-#ifndef _UTSNAME_RELEASE_LENGTH
-# define _UTSNAME_RELEASE_LENGTH _UTSNAME_LENGTH
-#endif
-#ifndef _UTSNAME_VERSION_LENGTH
-# define _UTSNAME_VERSION_LENGTH _UTSNAME_LENGTH
-#endif
-#ifndef _UTSNAME_MACHINE_LENGTH
-# define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH
-#endif
+# ifndef _UTSNAME_NODENAME_LENGTH
+#  define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH
+# endif
+# ifndef _UTSNAME_SYSNAME_LENGTH
+#  define _UTSNAME_SYSNAME_LENGTH _UTSNAME_LENGTH
+# endif
+# ifndef _UTSNAME_RELEASE_LENGTH
+#  define _UTSNAME_RELEASE_LENGTH _UTSNAME_LENGTH
+# endif
+# ifndef _UTSNAME_VERSION_LENGTH
+#  define _UTSNAME_VERSION_LENGTH _UTSNAME_LENGTH
+# endif
+# ifndef _UTSNAME_MACHINE_LENGTH
+#  define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH
+# endif
 
 /* Structure describing the system and machine.  */
 struct utsname
@@ -63,6 +72,7 @@
     /* Name of the hardware type the system is running on.  */
     char machine[_UTSNAME_MACHINE_LENGTH];
   };
+#endif /* !@HAVE_STRUCT_UTSNAME@ */
 
 
 #if @GNULIB_UNAME@
--- a/m4/sys_times_h.m4
+++ b/m4/sys_times_h.m4
@@ -1,4 +1,5 @@
 # Configure a replacement for <sys/times.h>.
+# serial 2
 
 # Copyright (C) 2008, 2009 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -11,13 +12,21 @@
 [
   AC_REQUIRE([gl_SYS_TIMES_H_DEFAULTS])
 
+  gl_CHECK_NEXT_HEADERS([sys/times.h])
   AC_CHECK_HEADERS_ONCE([sys/times.h])
   if test $ac_cv_header_sys_times_h = yes; then
     SYS_TIMES_H=
+    HAVE_SYS_TIMES_H=1
+    AC_CHECK_TYPES([struct tms], [], [HAVE_STRUCT_TMS=0], [[
+#include <sys/times.h>
+      ]])
   else
     SYS_TIMES_H=sys/times.h
+    HAVE_SYS_TIMES_H=0
+    HAVE_STRUCT_TMS=0
   fi
   AC_SUBST([SYS_TIMES_H])
+  AC_SUBST([HAVE_SYS_TIMES_H])
 ])
 
 AC_DEFUN([gl_SYS_TIMES_MODULE_INDICATOR],
@@ -29,5 +38,7 @@
 
 AC_DEFUN([gl_SYS_TIMES_H_DEFAULTS],
 [
-  GNULIB_TIMES=0; AC_SUBST([GNULIB_TIMES])
+  GNULIB_TIMES=0;     AC_SUBST([GNULIB_TIMES])
+  HAVE_STRUCT_TMS=1;  AC_SUBST([HAVE_STRUCT_TMS])
+  HAVE_TIMES=1;       AC_SUBST([HAVE_TIMES])
 ])
--- a/m4/sys_utsname_h.m4
+++ b/m4/sys_utsname_h.m4
@@ -1,4 +1,4 @@
-# sys_utsname_h.m4 serial 1
+# sys_utsname_h.m4 serial 2
 dnl Copyright (C) 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -12,10 +12,19 @@
   dnl once only, before all statements that occur in other macros.
   AC_REQUIRE([gl_SYS_UTSNAME_H_DEFAULTS])
 
+  gl_CHECK_NEXT_HEADERS([sys/utsname.h])
   AC_CHECK_HEADERS_ONCE([sys/utsname.h])
   if test $ac_cv_header_sys_utsname_h != yes; then
     SYS_UTSNAME_H='sys/utsname.h'
+    HAVE_SYS_UTSNAME_H=0
+    HAVE_STRUCT_UTSNAME=0
+  else
+    HAVE_SYS_UTSNAME_H=1
+    AC_CHECK_TYPES([struct utsname], [], [HAVE_STRUCT_UTSNAME=0], [[
+#include <sys/utsname.h>
+      ]])
   fi
+  AC_SUBST([HAVE_SYS_UTSNAME_H])
 ])
 
 AC_DEFUN([gl_SYS_UTSNAME_MODULE_INDICATOR],
@@ -27,8 +36,9 @@
 
 AC_DEFUN([gl_SYS_UTSNAME_H_DEFAULTS],
 [
-  GNULIB_UNAME=0;   AC_SUBST([GNULIB_UNAME])
+  GNULIB_UNAME=0;         AC_SUBST([GNULIB_UNAME])
   dnl Assume proper GNU behavior unless another module says otherwise.
-  HAVE_UNAME=1;     AC_SUBST([HAVE_UNAME])
-  SYS_UTSNAME_H=''; AC_SUBST([SYS_UTSNAME_H])
+  HAVE_UNAME=1;           AC_SUBST([HAVE_UNAME])
+  HAVE_STRUCT_UTSNAME=1;  AC_SUBST([HAVE_STRUCT_UTSNAME])
+  SYS_UTSNAME_H='';       AC_SUBST([SYS_UTSNAME_H])
 ])
--- a/modules/sys_times
+++ b/modules/sys_times
@@ -6,8 +6,9 @@
 m4/sys_times_h.m4
 
 Depends-on:
+arg-nonnull
+include_next
 link-warning
-arg-nonnull
 
 configure.ac:
 gl_SYS_TIMES_H
@@ -22,7 +23,13 @@
 	$(AM_V_at)$(MKDIR_P) sys
 	$(AM_V_GEN)rm -f $@-t $@ && \
 	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-	  sed -e 's|@''GNULIB_TIMES''@|$(GNULIB_TIMES)|g' \
+	  sed -e 's/@''HAVE_SYS_TIMES_H''@/$(HAVE_SYS_TIMES_H)/g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''NEXT_SYS_TIMES_H''@|$(NEXT_SYS_TIMES_H)|g' \
+	      -e 's|@''GNULIB_TIMES''@|$(GNULIB_TIMES)|g' \
+	      -e 's|@''HAVE_STRUCT_TMS''@|$(HAVE_STRUCT_TMS)|g' \
+	      -e 's|@''HAVE_TIMES''@|$(HAVE_TIMES)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
 	      < $(srcdir)/sys_times.in.h; \
--- a/modules/sys_utsname
+++ b/modules/sys_utsname
@@ -6,8 +6,9 @@
 m4/sys_utsname_h.m4
 
 Depends-on:
+arg-nonnull
+include_next
 link-warning
-arg-nonnull
 
 configure.ac:
 gl_SYS_UTSNAME_H
@@ -22,7 +23,12 @@
 	$(AM_V_at)$(MKDIR_P) sys
 	$(AM_V_GEN)rm -f $@-t $@ && \
 	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-	  sed -e 's|@''GNULIB_UNAME''@|$(GNULIB_UNAME)|g' \
+	  sed -e 's/@''HAVE_SYS_UTSNAME_H''@/$(HAVE_SYS_UTSNAME_H)/g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''NEXT_SYS_UTSNAME_H''@|$(NEXT_SYS_UTSNAME_H)|g' \
+	      -e 's|@''GNULIB_UNAME''@|$(GNULIB_UNAME)|g' \
+	      -e 's|@''HAVE_STRUCT_UTSNAME''@|$(HAVE_STRUCT_UTSNAME)|g' \
 	      -e 's|@''HAVE_UNAME''@|$(HAVE_UNAME)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
--- a/tests/test-sys_times.c
+++ b/tests/test-sys_times.c
@@ -20,10 +20,11 @@
 
 #include <sys/times.h>
 
-struct tms tms;
+static struct tms tms;
 
 int
 main (void)
 {
-  return 0;
+  clock_t t = tms.tms_utime + tms.tms_stime + tms.tms_cutime + tms.tms_cstime;
+  return t;
 }