sys_times, sys_utsname: use include_next
authorEric Blake <ebb9@byu.net>
Wed, 30 Dec 2009 16:47:55 +0000 (09:47 -0700)
committerEric Blake <ebb9@byu.net>
Thu, 31 Dec 2009 13:03:31 +0000 (06:03 -0700)
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>
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

index ffecc44..2b82077 100644 (file)
--- 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.
index 2af1e58..31ab4ce 100644 (file)
    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 @@ extern "C" {
     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)                                              \
index 2a26348..0e3d7cd 100644 (file)
    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.  */
 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 @@ struct utsname
     /* Name of the hardware type the system is running on.  */
     char machine[_UTSNAME_MACHINE_LENGTH];
   };
+#endif /* !@HAVE_STRUCT_UTSNAME@ */
 
 
 #if @GNULIB_UNAME@
index aaff00a..2fe9f24 100644 (file)
@@ -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_DEFUN([gl_SYS_TIMES_H],
 [
   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_MODULE_INDICATOR],
 
 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])
 ])
index 2e688fb..84b781f 100644 (file)
@@ -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 @@ AC_DEFUN([gl_SYS_UTSNAME_H],
   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_MODULE_INDICATOR],
 
 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])
 ])
index 23af537..8ccf5da 100644 (file)
@@ -6,8 +6,9 @@ lib/sys_times.in.h
 m4/sys_times_h.m4
 
 Depends-on:
-link-warning
 arg-nonnull
+include_next
+link-warning
 
 configure.ac:
 gl_SYS_TIMES_H
@@ -22,7 +23,13 @@ sys/times.h: sys_times.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H)
        $(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; \
index 83e337d..cdb3468 100644 (file)
@@ -6,8 +6,9 @@ lib/sys_utsname.in.h
 m4/sys_utsname_h.m4
 
 Depends-on:
-link-warning
 arg-nonnull
+include_next
+link-warning
 
 configure.ac:
 gl_SYS_UTSNAME_H
@@ -22,7 +23,12 @@ sys/utsname.h: sys_utsname.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H)
        $(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)' \
index 5f36747..22e4bc6 100644 (file)
 
 #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;
 }