New module 'time', so that apps can include <time.h> as per
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Feb 2007 18:49:19 +0000 (18:49 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Feb 2007 18:49:19 +0000 (18:49 +0000)
POSIX and GNU instead of separate include files like time_r.h
and timegm.h.  This implementation tries out a simpler approach
for replacing decls in standard include files (as compared to
the string module), somewhat as an experiment.

* config/srclist.txt: Comment out mktime.c for now.
* doc/gnulib-tool.texi (Initial import): Don't use time_r as an example
since it doesn't apply any more.  Use generic wording instead.
* MODULES.html.sh (Support for systems lacking POSIX:2001): New module
'time'.
* lib/time_.h, m4/time_h.m4, modules/time: New files.
* lib/strptime.h, lib/time_r.h, lib/timegm.h: Remove.
* lib/mktime.c: Include config.h depending on _LIBC, not HAVE_CONFIG_H.
Don't include <sys/types.h>; no longer needed since we assume C89.
* lib/mktime.c: Don't include "time_r.h"; no longer needed.
* lib/strftime.c: Likewise.
* lib/time_r.c: Likewise.
* lib/nanosleep.c (nanosleep): #undef after include files, not before.
* lib/nanosleep.c: Include <time.h> first, to check interface.
* lib/strptime.c: Likewise.
* lib/time_r.c: Likewise.
* lib/timegm.c: Likewise.
* lib/strptime.c: Don't include strptime.h or time_r.h; no longer
needed.
* lib/timegm.c: Don't include timegm.h; no longer needed.
* lib/timespec.h: Don't include <sys/time.h> before <time.h>;
time.h now handles any problems in that area.
(struct timespec, nanosleep): Remove; time.h now arranges for these.
* lib/xnanosleep.c: Don't include timespec.h; no longer needed now
that time.h defines struct timespec.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Check that nanosleep is declared.
Set REPLACE_NANOSLEEP.  Don't AC_DEFINE nanosleep; the time module now
handles that.
* m4/strptime.m4 (gl_FUNC_STPRTIME): Set REPLACE_STRPTIME.
* m4/time_r.m4 (gl_TIME_R): Don't define HAVE_TIME_R_POSIX; no longer
needed.  Set REPLACE_LOCALTIME.
* m4/timegm.m4 (gl_FUNC_TIMEGM): Set REPLACE_TIMEGM.
* m4/timespec.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Move to time_h.m4.
(gl_TIMESPEC): Don't check for sys/time.h or struct timespec or
nanosleep; time_h.m4 now does that.  Don't require
gl_USE_SYSTEM_EXTENSIONS; no longer needed directly, and the time
module handles this now.
* modules/getdate (Depends-on): Remove timespec.  Add time.
* modules/nanosleep (Depends-on): Likewise.
* modules/stat-time (Depends-on): Likewise.
* modules/nanosleep (Include): Include time.h, not timespec.h.
* modules/strptime (Files): Remove lib/strptime.h.
(Depends-on): Add extensions, time.
(Include): Include time.h, not strptime.h.
* modules/time_r (Files): Remove lib/time_r.h.
(Depends-on): Add time.
(Include): Include time.h, not time_r.h.
* modules/timegm: Likewise.
* modules/timespec (Description): Now does timespec-related decls
of our own, instead of struct timespec itself.
(Depends-on): Add time; remove extensions.
(Maintainer): Add self.
* modules/utimecmp (Depends-on): Add time; remove timespec.
* modules/utimens (Depends-on): Likewise.
* modules/xnanosleep (Depends-on): Likewise.

33 files changed:
ChangeLog
MODULES.html.sh
config/srclist.txt
doc/gnulib-tool.texi
lib/mktime.c
lib/nanosleep.c
lib/strftime.c
lib/strptime.c
lib/strptime.h [deleted file]
lib/time_.h [new file with mode: 0644]
lib/time_r.c
lib/time_r.h [deleted file]
lib/timegm.c
lib/timegm.h [deleted file]
lib/timespec.h
lib/xnanosleep.c
m4/nanosleep.m4
m4/strptime.m4
m4/time_h.m4 [new file with mode: 0644]
m4/time_r.m4
m4/timegm.m4
m4/timespec.m4
modules/getdate
modules/nanosleep
modules/stat-time
modules/strptime
modules/time [new file with mode: 0644]
modules/time_r
modules/timegm
modules/timespec
modules/utimecmp
modules/utimens
modules/xnanosleep

index d8a45a8..56d9e12 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,67 @@
+2007-02-12  Paul Eggert  <eggert@cs.ucla.edu>
+
+       New module 'time', so that apps can include <time.h> as per
+       POSIX and GNU instead of separate include files like time_r.h
+       and timegm.h.  This implementation tries out a simpler approach
+       for replacing decls in standard include files (as compared to
+       the string module), somewhat as an experiment.
+
+       * config/srclist.txt: Comment out mktime.c for now.
+       * doc/gnulib-tool.texi (Initial import): Don't use time_r as an example
+       since it doesn't apply any more.  Use generic wording instead.
+       * MODULES.html.sh (Support for systems lacking POSIX:2001): New module
+       'time'.
+       * lib/time_.h, m4/time_h.m4, modules/time: New files.
+       * lib/strptime.h, lib/time_r.h, lib/timegm.h: Remove.
+       * lib/mktime.c: Include config.h depending on _LIBC, not HAVE_CONFIG_H.
+       Don't include <sys/types.h>; no longer needed since we assume C89.
+       * lib/mktime.c: Don't include "time_r.h"; no longer needed.
+       * lib/strftime.c: Likewise.
+       * lib/time_r.c: Likewise.
+       * lib/nanosleep.c (nanosleep): #undef after include files, not before.
+       * lib/nanosleep.c: Include <time.h> first, to check interface.
+       * lib/strptime.c: Likewise.
+       * lib/time_r.c: Likewise.
+       * lib/timegm.c: Likewise.
+       * lib/strptime.c: Don't include strptime.h or time_r.h; no longer
+       needed.
+       * lib/timegm.c: Don't include timegm.h; no longer needed.
+       * lib/timespec.h: Don't include <sys/time.h> before <time.h>;
+       time.h now handles any problems in that area.
+       (struct timespec, nanosleep): Remove; time.h now arranges for these.
+       * lib/xnanosleep.c: Don't include timespec.h; no longer needed now
+       that time.h defines struct timespec.
+       * m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Check that nanosleep is declared.
+       Set REPLACE_NANOSLEEP.  Don't AC_DEFINE nanosleep; the time module now
+       handles that.
+       * m4/strptime.m4 (gl_FUNC_STPRTIME): Set REPLACE_STRPTIME.
+       * m4/time_r.m4 (gl_TIME_R): Don't define HAVE_TIME_R_POSIX; no longer
+       needed.  Set REPLACE_LOCALTIME.
+       * m4/timegm.m4 (gl_FUNC_TIMEGM): Set REPLACE_TIMEGM.
+       * m4/timespec.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Move to time_h.m4.
+       (gl_TIMESPEC): Don't check for sys/time.h or struct timespec or
+       nanosleep; time_h.m4 now does that.  Don't require
+       gl_USE_SYSTEM_EXTENSIONS; no longer needed directly, and the time
+       module handles this now.
+       * modules/getdate (Depends-on): Remove timespec.  Add time.
+       * modules/nanosleep (Depends-on): Likewise.
+       * modules/stat-time (Depends-on): Likewise.
+       * modules/nanosleep (Include): Include time.h, not timespec.h.
+       * modules/strptime (Files): Remove lib/strptime.h.
+       (Depends-on): Add extensions, time.
+       (Include): Include time.h, not strptime.h.
+       * modules/time_r (Files): Remove lib/time_r.h.
+       (Depends-on): Add time.
+       (Include): Include time.h, not time_r.h.
+       * modules/timegm: Likewise.
+       * modules/timespec (Description): Now does timespec-related decls
+       of our own, instead of struct timespec itself.
+       (Depends-on): Add time; remove extensions.
+       (Maintainer): Add self.
+       * modules/utimecmp (Depends-on): Add time; remove timespec.
+       * modules/utimens (Depends-on): Likewise.
+       * modules/xnanosleep (Depends-on): Likewise.
+
 2007-02-11  Bruno Haible  <bruno@clisp.org>
 
        * lib/c-strstr.c: Include allocsa.h.
index 4e42b80..63b16c9 100755 (executable)
@@ -1950,6 +1950,7 @@ func_all_modules ()
   func_module readlink
   func_module lstat
   func_module tempname
+  func_module time
   func_module time_r
   func_module timespec
   func_module nanosleep
index 9f9e9f7..71ca0fc 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: srclist.txt,v 1.144 2007-02-10 14:46:17 karl Exp $
+# $Id: srclist.txt,v 1.145 2007-02-12 18:49:19 eggert Exp $
 # Files for which we are not the source.  See ./srclistvars.sh for the
 # variable definitions.
 
@@ -196,7 +196,7 @@ $LIBCSRC/stdlib/strtoll.c           lib gpl
 $LIBCSRC/stdlib/strtoul.c              lib gpl
 # (no more strtok_r.h) $LIBCSRC/string/strtok_r.c              lib gpl
 # (gnulib needs config.h?) $LIBCSRC/string/memmem.c            lib gpl
-$LIBCSRC/time/mktime.c                 lib gpl
+#$LIBCSRC/time/mktime.c                        lib gpl
 
 #
 # http://sourceware.org/bugzilla/show_bug.cgi?id=1439
index ca49a17..c2ea0a6 100644 (file)
@@ -229,17 +229,15 @@ example, you would need to make sure that @samp{#include <string.h>}
 is evaluated when compiling all source code files, that want to make
 use of @code{strdup}.
 
-When an include file is provided by Gnulib
-you shouldn't try to include the corresponding system header files
-yourself, but let the gnulib header file do it.  The ordering
-of the definition for some symbols may be significant; the Gnulib
-header files take care of that.
-
-For example, to use the @code{time_r} gnulib module you should
-use include header file provided by the gnulib, and so
-@samp{#include "time_r.h"}, but you shouldn't explicitly
-@samp{#include <time.h>} as it is already done in @file{time_r.h}
-before the redefinition of some symbols.
+In the usual case where Autoconf is creating a @file{config.h} file,
+you should include @file{config.h} first, before any other include
+file.  That way, for example, if @file{config.h} defines
+@samp{restrict} to be the empty string on a pre-C99 host, the
+definition is consistent for all include files.
+
+You should include Gnulib-provided headers before system headers,
+so that Gnulib-provided headers can adjust how a system header
+behaves.
 
 A final word of warning: Gnulib currently assumes it will be
 responsible for @emph{all} functions that end up in the Autoconf
index ded3295..a91fb20 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert a `struct tm' to a time_t value.
-   Copyright (C) 1993-1999, 2002-2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1993-1999, 2002-2005, 2006, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Paul Eggert <eggert@twinsun.com>.
 
@@ -21,7 +21,7 @@
    mktime.  */
 /* #define DEBUG 1 */
 
-#ifdef HAVE_CONFIG_H
+#ifndef _LIBC
 # include <config.h>
 #endif
 
@@ -32,7 +32,6 @@
 # define LEAP_SECONDS_POSSIBLE 1
 #endif
 
-#include <sys/types.h>         /* Some systems define `time_t' here.  */
 #include <time.h>
 
 #include <limits.h>
@@ -141,11 +140,10 @@ const unsigned short int __mon_yday[2][13] =
 
 
 #ifndef _LIBC
-/* Portable standalone applications should supply a "time_r.h" that
+/* Portable standalone applications should supply a <time.h> that
    declares a POSIX-compliant localtime_r, for the benefit of older
    implementations that lack localtime_r or have a nonstandard one.
    See the gnulib time_r module for one way to implement this.  */
-# include "time_r.h"
 # undef __localtime_r
 # define __localtime_r localtime_r
 # define __mktime_internal mktime_internal
index bb47268..89c5512 100644 (file)
@@ -21,9 +21,7 @@
 
 #include <config.h>
 
-/* Undefine nanosleep here so any prototype is not redefined to be a
-   prototype for rpl_nanosleep. (they'd conflict e.g., on alpha-dec-osf3.2)  */
-#undef nanosleep
+#include <time.h>
 
 #include "timespec.h"
 
 #include <signal.h>
 
 #include <sys/time.h>
-#include <time.h>
-
 #include <errno.h>
 
 #include <unistd.h>
 
+#undef nanosleep
+
 enum { BILLION = 1000 * 1000 * 1000 };
 
 #if HAVE_BUG_BIG_NANOSLEEP
index 3fce99b..1c202c9 100644 (file)
@@ -134,11 +134,10 @@ extern char *tzname[];
 #endif
 
 #if !HAVE_TM_GMTOFF
-/* Portable standalone applications should supply a "time_r.h" that
+/* Portable standalone applications should supply a "time.h" that
    declares a POSIX-compliant localtime_r, for the benefit of older
    implementations that lack localtime_r or have a nonstandard one.
    See the gnulib time_r module for one way to implement this.  */
-# include "time_r.h"
 # undef __gmtime_r
 # undef __localtime_r
 # define __gmtime_r gmtime_r
index 9373b45..c5a039d 100644 (file)
 
 #ifndef _LIBC
 # include <config.h>
-# include "strptime.h"
 #endif
 
+#include <time.h>
+
 #include <assert.h>
 #include <ctype.h>
 #ifdef _LIBC
@@ -27,7 +28,6 @@
 #endif
 #include <limits.h>
 #include <string.h>
-#include <time.h>
 #include <stdbool.h>
 
 #ifdef _LIBC
@@ -35,7 +35,6 @@
 #endif
 
 #ifndef _LIBC
-# include "time_r.h"
 enum ptime_locale_status { not, loc, raw };
 #endif
 
diff --git a/lib/strptime.h b/lib/strptime.h
deleted file mode 100644 (file)
index 9705741..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Convert a string representation of time to a tm structure.
-   Copyright (C) 2001-2003, 2005, 2007 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef GNULIB_STRPTIME_H_
-#define GNULIB_STRPTIME_H_
-
-#include <time.h>
-
-#if ! HAVE_STRPTIME
-/* See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/strptime.html>.  */
-extern char *strptime (const char *restrict s, const char *restrict format,
-                      struct tm *restrict tm);
-#endif
-
-#endif /* GNULIB_STRPTIME_H_ */
diff --git a/lib/time_.h b/lib/time_.h
new file mode 100644 (file)
index 0000000..7403270
--- /dev/null
@@ -0,0 +1,107 @@
+/* A more-standard <time.h>.
+
+   Copyright (C) 2007 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Don't get in the way of glibc when it includes time.h merely to
+   declare a few standard symbols, rather than to declare all the
+   symbols.  */
+#if defined __need_time_t || defined __need_clock_t || defined __need_timespec
+# include @ABSOLUTE_TIME_H@
+
+#elif ! defined _GL_TIME_H
+# define _GL_TIME_H
+# include @ABSOLUTE_TIME_H@
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
+   Or they define it with the wrong member names or define it in <sys/time.h>
+   (e.g., FreeBSD circa 1997).  */
+# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
+#  if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
+#   include <sys/time.h>
+#  else
+#   undef timespec
+#   define timespec rpl_timespec
+struct timespec
+{
+  time_t tv_sec;
+  long int tv_nsec;
+};
+#  endif
+# endif
+
+/* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
+   return -1 and store the remaining time into RMTP.  See
+   <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
+# if @REPLACE_NANOSLEEP@
+#  define nanosleep rpl_nanosleep
+int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp);
+# endif
+
+/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
+   <http://www.opengroup.org/susv3xsh/localtime_r.html> and
+   <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
+# if @REPLACE_LOCALTIME_R@
+#  undef localtime_r
+#  define localtime_r rpl_localtime_r
+#  undef gmtime_r
+#  define gmtime_r rpl_gmtime_r
+struct tm *localtime_r (time_t const *restrict __timer,
+                       struct tm *restrict __result);
+struct tm *gmtime_r (time_t const *restrict __timer,
+                    struct tm *restrict __result);
+# endif
+
+/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
+   the resulting broken-down time into TM.  See
+   <http://www.opengroup.org/susv3xsh/strptime.html>.  */
+# if @REPLACE_STRPTIME@
+#  undef strptime
+#  define strptime rpl_strptime
+char *strptime (char const *restrict __buf, char const *restrict __format,
+               struct tm *restrict __tm);
+# endif
+
+/* Convert TM to a time_t value, assuming UTC.  */
+# if @REPLACE_TIMEGM@
+#  undef timegm
+#  define timegm rpl_timegm
+time_t timegm (struct tm *__tm);
+#endif
+
+/* Encourage applications to avoid unsafe functions that can overrrun
+   buffers when given outlandish struct tm values.  Portable
+   applications should use strftime (or even sprintf) instead.  */
+# if GNULIB_PORTCHECK
+#  undef asctime
+#  define asctime eschew_asctime
+#  undef asctime_r
+#  define asctime_r eschew_asctime_r
+#  undef ctime
+#  define ctime eschew_ctime
+#  undef ctime_r
+#  define ctime_r eschew_ctime_r
+# endif
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
index 3205862..2b72692 100644 (file)
@@ -1,6 +1,6 @@
 /* Reentrant time functions like localtime_r.
 
-   Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
 
 #include <config.h>
 
-#include "time_r.h"
+#include <time.h>
 
 #include <string.h>
 
diff --git a/lib/time_r.h b/lib/time_r.h
deleted file mode 100644 (file)
index ba8b070..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Reentrant time functions like localtime_r.
-
-   Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Paul Eggert.  */
-
-#ifndef _TIME_R_H
-#define _TIME_R_H
-
-/* Include <time.h> first, since it may declare these functions with
-   signatures that disagree with POSIX, and we don't want to rename
-   those declarations.  */
-#include <time.h>
-
-#if !HAVE_TIME_R_POSIX
-
-/* Don't bother with asctime_r and ctime_r, since these functions are
-   not safe (like asctime and ctime, they can overrun their 26-byte
-   output buffers when given outlandish struct tm values), and we
-   don't want to encourage applications to use unsafe functions.  Use
-   strftime or even sprintf instead.  */
-
-# undef gmtime_r
-# undef localtime_r
-
-# define gmtime_r rpl_gmtime_r
-# define localtime_r rpl_localtime_r
-
-/* See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/gmtime.html>.  */
-struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
-
-/* See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/localtime.html>.  */
-struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
-#endif
-
-#endif
index 656df1c..67230cf 100644 (file)
@@ -1,6 +1,6 @@
 /* Convert UTC calendar time to simple time.  Like mktime but assumes UTC.
 
-   Copyright (C) 1994, 1997, 2003, 2004, 2006 Free Software
+   Copyright (C) 1994, 1997, 2003, 2004, 2006, 2007 Free Software
    Foundation, Inc.  This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifdef _LIBC
-# include <time.h>
-#else
+#ifndef _LIBC
 # include <config.h>
-# include "timegm.h"
-# include <time_r.h>
+#endif
+
+#include <time.h>
+
+#ifndef _LIBC
 # undef __gmtime_r
 # define __gmtime_r gmtime_r
 # define __mktime_internal mktime_internal
diff --git a/lib/timegm.h b/lib/timegm.h
deleted file mode 100644 (file)
index ee513f4..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Convert UTC calendar time to simple time.  Like mktime but assumes UTC.
-
-   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include <time.h>
-
-#if defined HAVE_DECL_TIMEGM && !HAVE_DECL_TIMEGM
-time_t timegm (struct tm *tm);
-#endif
index c652577..cce2d66 100644 (file)
 #if ! defined TIMESPEC_H
 # define TIMESPEC_H
 
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# endif
 # include <time.h>
 
-# if ! HAVE_STRUCT_TIMESPEC
-/* Some systems don't define this struct, e.g., AIX 4.1, Ultrix 4.3.  */
-struct timespec
-{
-  time_t tv_sec;
-  long int tv_nsec;
-};
-# endif
-
 /* Return negative, zero, positive if A < B, A == B, A > B, respectively.
    Assume the nanosecond components are in range, or close to it.  */
 static inline int
@@ -43,12 +31,6 @@ timespec_cmp (struct timespec a, struct timespec b)
          : a.tv_nsec - b.tv_nsec);
 }
 
-# if ! HAVE_DECL_NANOSLEEP
-/* Don't specify a prototype here.  Some systems (e.g., OSF) declare
-   nanosleep with a conflicting one (const-less first parameter).  */
-int nanosleep ();
-# endif
-
 void gettime (struct timespec *);
 int settime (struct timespec const *);
 
index 70c7f2a..ebbd7ee 100644 (file)
@@ -1,6 +1,7 @@
 /* xnanosleep.c -- a more convenient interface to nanosleep
 
-   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software
+   Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -32,7 +33,6 @@
 #include <time.h>
 
 #include "intprops.h"
-#include "timespec.h"
 
 #ifndef TIME_T_MAX
 # define TIME_T_MAX TYPE_MAXIMUM (time_t)
index d25295e..af346b6 100644 (file)
@@ -1,4 +1,4 @@
-#serial 20
+#serial 21
 
 dnl From Jim Meyering.
 dnl Check for the nanosleep function.
@@ -67,6 +67,7 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
          ts_sleep.tv_nsec = 999999999;
          alarm (1);
          if (nanosleep (&ts_sleep, &ts_remaining) == -1 && errno == EINTR
+             && nanosleep
              && TYPE_MAXIMUM (time_t) - 10 < ts_remaining.tv_sec)
            return 0;
          return 119;
@@ -78,7 +79,10 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
       esac],
      [gl_cv_func_nanosleep=cross-compiling])
   ])
-  if test "$gl_cv_func_nanosleep" != yes; then
+  if test "$gl_cv_func_nanosleep" = yes; then
+    REPLACE_NANOSLEEP=0
+  else
+    REPLACE_NANOSLEEP=1
     if test "$gl_cv_func_nanosleep" = 'no (mishandles large arguments)'; then
       AC_DEFINE([HAVE_BUG_BIG_NANOSLEEP], 1,
        [Define to 1 if nanosleep mishandle large arguments.])
@@ -90,8 +94,6 @@ AC_DEFUN([gl_FUNC_NANOSLEEP],
       done
     fi
     AC_LIBOBJ(nanosleep)
-    AC_DEFINE(nanosleep, rpl_nanosleep,
-      [Define to rpl_nanosleep if the replacement function should be used.])
     gl_PREREQ_NANOSLEEP
   fi
 
index e1236b9..5f91998 100644 (file)
@@ -1,4 +1,4 @@
-# strptime.m4 serial 2
+# strptime.m4 serial 3
 dnl Copyright (C) 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,4 +9,9 @@ AC_DEFUN([gl_FUNC_STRPTIME],
   AC_REQUIRE([AC_C_RESTRICT])
   AC_REPLACE_FUNCS(strptime)
   AC_REQUIRE([gl_TM_GMTOFF])
+  if test $ac_cv_func_strptime = yes; then
+    REPLACE_STRPTIME=0
+  else
+    REPLACE_STRPTIME=1
+  fi
 ])
diff --git a/m4/time_h.m4 b/m4/time_h.m4
new file mode 100644 (file)
index 0000000..e90ed7a
--- /dev/null
@@ -0,0 +1,76 @@
+# Configure a more-standard replacement for <time.h>.
+
+# Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2007 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.
+
+# Written by Paul Eggert and Jim Meyering.
+
+AC_DEFUN([gl_HEADER_TIME_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_HEADER_TIME_H_BODY])
+])
+
+AC_DEFUN([gl_HEADER_TIME_H_BODY],
+[
+  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
+  gl_ABSOLUTE_HEADER([time.h])
+  ABSOLUTE_TIME_H=\"$gl_cv_absolute_time_h\"
+  AC_SUBST([ABSOLUTE_TIME_H])
+  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
+])
+
+AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
+[
+  dnl If another module says to replace or to not replace, do that.
+  dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
+  dnl this lets maintainers check for portability.
+  REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;  AC_SUBST([REPLACE_LOCALTIME_R])
+  REPLACE_NANOSLEEP=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_NANOSLEEP])
+  REPLACE_STRPTIME=GNULIB_PORTCHECK;     AC_SUBST([REPLACE_STRPTIME])
+  REPLACE_TIMEGM=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_TIMEGM])
+])
+
+dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
+dnl in time.h or sys/time.h.
+
+AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
+[
+  AC_CHECK_HEADERS_ONCE([sys/time.h])
+  AC_CACHE_CHECK([for struct timespec in <time.h>],
+    [gl_cv_sys_struct_timespec_in_time_h],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+         [[#include <time.h>
+         ]],
+         [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
+       [gl_cv_sys_struct_timespec_in_time_h=yes],
+       [gl_cv_sys_struct_timespec_in_time_h=no])])
+
+  TIME_H_DEFINES_STRUCT_TIMESPEC=0
+  SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
+  if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
+    TIME_H_DEFINES_STRUCT_TIMESPEC=1
+  else
+    AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
+      [gl_cv_sys_struct_timespec_in_sys_time_h],
+      [AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM(
+           [[#include <sys/time.h>
+           ]],
+           [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
+        [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
+        [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
+    if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
+      SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
+    fi
+  fi
+  AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
+  AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
+])
index ac8353a..a4e016f 100644 (file)
@@ -1,6 +1,6 @@
 dnl Reentrant time functions like localtime_r.
 
-dnl Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+dnl Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc.
 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.
@@ -24,10 +24,9 @@ AC_DEFUN([gl_TIME_R],
        [gl_cv_time_r_posix=yes],
        [gl_cv_time_r_posix=no])])
   if test $gl_cv_time_r_posix = yes; then
-    AC_DEFINE([HAVE_TIME_R_POSIX], 1,
-      [Define to 1 if localtime_r, etc. have the type signatures that
-       POSIX requires.])
+    REPLACE_LOCALTIME_R=0
   else
+    REPLACE_LOCALTIME_R=1
     AC_LIBOBJ([time_r])
     gl_PREREQ_TIME_R
   fi
index 82e9d66..51ffd0f 100644 (file)
@@ -1,5 +1,5 @@
-# timegm.m4 serial 3
-dnl Copyright (C) 2003 Free Software Foundation, Inc.
+# timegm.m4 serial 4
+dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc.
 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.
@@ -14,11 +14,13 @@ AC_DEFUN([gl_FUNC_TIMEGM],
   else
     AC_REPLACE_FUNCS(timegm)
   fi
-  if test $ac_cv_func_timegm = no; then
+  REPLACE_TIMEGM=1
+  if test $ac_cv_func_timegm = yes; then
+    AC_CHECK_DECLS([timegm], [REPLACE_TIMEGM=0], [], [#include <time.h>])
+  fi
+  if test $REPLACE_TIMEGM = 1; then
     gl_PREREQ_TIMEGM
   fi
-
-  AC_CHECK_DECLS([timegm], , , [#include <time.h>])
 ])
 
 # Prerequisites of lib/timegm.c.
index 3305fd7..36f1238 100644 (file)
@@ -1,4 +1,4 @@
-#serial 13
+#serial 14
 
 # Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software
 # Foundation, Inc.
@@ -13,38 +13,4 @@ AC_DEFUN([gl_TIMESPEC],
 [
   dnl Prerequisites of lib/timespec.h.
   AC_REQUIRE([AC_C_INLINE])
-  AC_CHECK_HEADERS_ONCE(sys/time.h)
-  gl_CHECK_TYPE_STRUCT_TIMESPEC
-
-  dnl Persuade glibc and Solaris <time.h> to declare nanosleep.
-  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
-
-  AC_CHECK_DECLS(nanosleep, , , [#include <time.h>])
-])
-
-dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
-dnl in time.h or sys/time.h.
-
-AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
-[
-  dnl Persuade pedantic Solaris to declare struct timespec.
-  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
-
-  AC_CHECK_HEADERS_ONCE(sys/time.h)
-  AC_CACHE_CHECK([for struct timespec], [gl_cv_sys_struct_timespec],
-    [AC_COMPILE_IFELSE(
-       [AC_LANG_PROGRAM(
-         [[#if HAVE_SYS_TIME_H
-            #include <sys/time.h>
-           #endif
-           #include <time.h>
-         ]],
-         [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
-       [gl_cv_sys_struct_timespec=yes],
-       [gl_cv_sys_struct_timespec=no])])
-
-  if test $gl_cv_sys_struct_timespec = yes; then
-    AC_DEFINE(HAVE_STRUCT_TIMESPEC, 1,
-             [Define if struct timespec is declared in <time.h>. ])
-  fi
 ])
index ae5584e..653fd7a 100644 (file)
@@ -10,11 +10,11 @@ m4/tm_gmtoff.m4
 m4/getdate.m4
 
 Depends-on:
-timespec
 stdbool
 gettime
 mktime
 setenv
+time
 xalloc
 
 configure.ac:
index 4cc7f52..e7dfac4 100644 (file)
@@ -10,7 +10,7 @@ clock-time
 extensions
 stdbool
 sys_time
-timespec
+time
 
 configure.ac:
 gl_FUNC_NANOSLEEP
@@ -18,7 +18,7 @@ gl_FUNC_NANOSLEEP
 Makefile.am:
 
 Include:
-"timespec.h"
+<time.h>
 
 Link:
 $(LIB_NANOSLEEP)
index 666f4ed..13dc911 100644 (file)
@@ -6,7 +6,7 @@ lib/stat-time.h
 m4/stat-time.m4
 
 Depends-on:
-timespec
+time
 
 configure.ac:
 gl_STAT_TIME
index 690c762..799170a 100644 (file)
@@ -2,16 +2,17 @@ Description:
 Convert a string representation of time to a tm structure.
 
 Files:
-lib/strptime.h
 lib/strptime.c
 m4/strptime.m4
 m4/tm_gmtoff.m4
 
 Depends-on:
+extensions
 sys_time
 string
 strcase
 stdbool
+time
 time_r
 
 configure.ac:
@@ -20,7 +21,7 @@ gl_FUNC_STRPTIME
 Makefile.am:
 
 Include:
-"strptime.h"
+<time.h>
 
 License:
 LGPL
diff --git a/modules/time b/modules/time
new file mode 100644 (file)
index 0000000..d93ee8d
--- /dev/null
@@ -0,0 +1,42 @@
+Description:
+A more-standard <time.h>.
+
+Files:
+lib/time_.h
+m4/time_h.m4
+
+Depends-on:
+absolute-header
+extensions
+
+configure.ac:
+gl_HEADER_TIME_H
+
+Makefile.am:
+BUILT_SOURCES += time.h
+
+# We need the following in order to create <time.h> when the system
+# doesn't have one that works with the given compiler.
+time.h: time_.h
+       rm -f $@-t $@
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+         sed -e 's|@ABSOLUTE_TIME_H''@|$(ABSOLUTE_TIME_H)|g' \
+             -e 's|@REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
+             -e 's|@REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
+             -e 's|@REPLACE_STRPTIME''@|$(REPLACE_STRPTIME)|g' \
+             -e 's|@REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
+             -e 's|@SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
+             -e 's|@TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
+             < $(srcdir)/time_.h; \
+       } > $@-t
+       mv $@-t $@
+MOSTLYCLEANFILES += time.h time.h-t
+
+Include:
+#include <time.h>
+
+License:
+LGPL
+
+Maintainer:
+all
index 96df2f7..a0ec5cd 100644 (file)
@@ -3,11 +3,11 @@ Reentrant time functions like localtime_r.
 
 Files:
 lib/time_r.c
-lib/time_r.h
 m4/time_r.m4
 
 Depends-on:
 extensions
+time
 
 configure.ac:
 gl_TIME_R
@@ -15,7 +15,7 @@ gl_TIME_R
 Makefile.am:
 
 Include:
-"time_r.h"
+<time.h>
 
 License:
 LGPL
index b73d59a..a8bb54b 100644 (file)
@@ -2,12 +2,12 @@ Description:
 Convert calendar time to simple time, inverse of mktime.
 
 Files:
-lib/timegm.h
 lib/timegm.c
 m4/timegm.m4
 
 Depends-on:
 mktime
+time
 time_r
 
 configure.ac:
@@ -16,7 +16,7 @@ gl_FUNC_TIMEGM
 Makefile.am:
 
 Include:
-"timegm.h"
+<time.h>
 
 License:
 LGPL
index edd2dfc..8d74632 100644 (file)
@@ -1,12 +1,12 @@
 Description:
-struct timespec.
+timespec-related declarations
 
 Files:
 lib/timespec.h
 m4/timespec.m4
 
 Depends-on:
-extensions
+time
 
 configure.ac:
 gl_TIMESPEC
@@ -20,4 +20,4 @@ License:
 GPL
 
 Maintainer:
-Jim Meyering
+Paul Eggert and Jim Meyering
index a042393..12da25e 100644 (file)
@@ -9,7 +9,7 @@ m4/utimecmp.m4
 Depends-on:
 hash
 stat-time
-timespec
+time
 utimens
 xalloc
 intprops
index c341f65..caf8805 100644 (file)
@@ -10,7 +10,7 @@ m4/utimes.m4
 
 Depends-on:
 sys_time
-timespec
+time
 
 configure.ac:
 gl_UTIMENS
index fa063cb..b8c758c 100644 (file)
@@ -8,7 +8,7 @@ m4/xnanosleep.m4
 
 Depends-on:
 nanosleep
-timespec
+time
 intprops
 stdbool