From 3ac9552429c5a500717e1d3d129c32f7d0ea37a3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 12 Feb 2007 18:49:19 +0000 Subject: [PATCH] New module 'time', so that apps can include 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 ; 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 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 before ; 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. --- ChangeLog | 64 ++++++++++++++++++++++++++++++ MODULES.html.sh | 1 + config/srclist.txt | 4 +- doc/gnulib-tool.texi | 20 +++++----- lib/mktime.c | 8 ++-- lib/nanosleep.c | 8 ++-- lib/strftime.c | 3 +- lib/strptime.c | 5 +-- lib/strptime.h | 30 --------------- lib/time_.h | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/time_r.c | 4 +- lib/time_r.h | 52 ------------------------- lib/timegm.c | 13 ++++--- lib/timegm.h | 23 ----------- lib/timespec.h | 18 --------- lib/xnanosleep.c | 4 +- m4/nanosleep.m4 | 10 +++-- m4/strptime.m4 | 7 +++- m4/time_h.m4 | 76 ++++++++++++++++++++++++++++++++++++ m4/time_r.m4 | 7 ++-- m4/timegm.m4 | 12 +++--- m4/timespec.m4 | 36 +---------------- modules/getdate | 2 +- modules/nanosleep | 4 +- modules/stat-time | 2 +- modules/strptime | 5 ++- modules/time | 42 ++++++++++++++++++++ modules/time_r | 4 +- modules/timegm | 4 +- modules/timespec | 6 +-- modules/utimecmp | 2 +- modules/utimens | 2 +- modules/xnanosleep | 2 +- 33 files changed, 361 insertions(+), 226 deletions(-) delete mode 100644 lib/strptime.h create mode 100644 lib/time_.h delete mode 100644 lib/time_r.h delete mode 100644 lib/timegm.h create mode 100644 m4/time_h.m4 create mode 100644 modules/time diff --git a/ChangeLog b/ChangeLog index d8a45a89b..56d9e122e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,67 @@ +2007-02-12 Paul Eggert + + New module 'time', so that apps can include 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 ; 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 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 before ; + 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 * lib/c-strstr.c: Include allocsa.h. diff --git a/MODULES.html.sh b/MODULES.html.sh index 4e42b80e6..63b16c998 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -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 diff --git a/config/srclist.txt b/config/srclist.txt index 9f9e9f791..71ca0fc21 100644 --- a/config/srclist.txt +++ b/config/srclist.txt @@ -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 diff --git a/doc/gnulib-tool.texi b/doc/gnulib-tool.texi index ca49a17d9..c2ea0a6ff 100644 --- a/doc/gnulib-tool.texi +++ b/doc/gnulib-tool.texi @@ -229,17 +229,15 @@ example, you would need to make sure that @samp{#include } 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 } 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 diff --git a/lib/mktime.c b/lib/mktime.c index ded3295c6..a91fb20e6 100644 --- a/lib/mktime.c +++ b/lib/mktime.c @@ -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 . @@ -21,7 +21,7 @@ mktime. */ /* #define DEBUG 1 */ -#ifdef HAVE_CONFIG_H +#ifndef _LIBC # include #endif @@ -32,7 +32,6 @@ # define LEAP_SECONDS_POSSIBLE 1 #endif -#include /* Some systems define `time_t' here. */ #include #include @@ -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 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 diff --git a/lib/nanosleep.c b/lib/nanosleep.c index bb4726812..89c551242 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -21,9 +21,7 @@ #include -/* 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 #include "timespec.h" @@ -36,12 +34,12 @@ #include #include -#include - #include #include +#undef nanosleep + enum { BILLION = 1000 * 1000 * 1000 }; #if HAVE_BUG_BIG_NANOSLEEP diff --git a/lib/strftime.c b/lib/strftime.c index 3fce99bd8..1c202c9b6 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -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 diff --git a/lib/strptime.c b/lib/strptime.c index 9373b45d7..c5a039da9 100644 --- a/lib/strptime.c +++ b/lib/strptime.c @@ -17,9 +17,10 @@ #ifndef _LIBC # include -# include "strptime.h" #endif +#include + #include #include #ifdef _LIBC @@ -27,7 +28,6 @@ #endif #include #include -#include #include #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 index 970574131..000000000 --- a/lib/strptime.h +++ /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 - -#if ! HAVE_STRPTIME -/* See the POSIX:2001 specification - . */ -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 index 000000000..740327087 --- /dev/null +++ b/lib/time_.h @@ -0,0 +1,107 @@ +/* A more-standard . + + 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 + (e.g., FreeBSD circa 1997). */ +# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ +# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ +# include +# 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 + . */ +# 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 + and + . */ +# 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 + . */ +# 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 diff --git a/lib/time_r.c b/lib/time_r.c index 3205862ad..2b7269284 100644 --- a/lib/time_r.c +++ b/lib/time_r.c @@ -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 -#include "time_r.h" +#include #include diff --git a/lib/time_r.h b/lib/time_r.h deleted file mode 100644 index ba8b0706b..000000000 --- a/lib/time_r.h +++ /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 first, since it may declare these functions with - signatures that disagree with POSIX, and we don't want to rename - those declarations. */ -#include - -#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 - . */ -struct tm *gmtime_r (time_t const * restrict, struct tm * restrict); - -/* See the POSIX:2001 specification - . */ -struct tm *localtime_r (time_t const * restrict, struct tm * restrict); -#endif - -#endif diff --git a/lib/timegm.c b/lib/timegm.c index 656df1c95..67230cf34 100644 --- a/lib/timegm.c +++ b/lib/timegm.c @@ -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 @@ -17,12 +17,13 @@ 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 -#else +#ifndef _LIBC # include -# include "timegm.h" -# include +#endif + +#include + +#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 index ee513f4e1..000000000 --- a/lib/timegm.h +++ /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 - -#if defined HAVE_DECL_TIMEGM && !HAVE_DECL_TIMEGM -time_t timegm (struct tm *tm); -#endif diff --git a/lib/timespec.h b/lib/timespec.h index c65257792..cce2d663a 100644 --- a/lib/timespec.h +++ b/lib/timespec.h @@ -19,20 +19,8 @@ #if ! defined TIMESPEC_H # define TIMESPEC_H -# if HAVE_SYS_TIME_H -# include -# endif # include -# 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 *); diff --git a/lib/xnanosleep.c b/lib/xnanosleep.c index 70c7f2a37..ebbd7ee89 100644 --- a/lib/xnanosleep.c +++ b/lib/xnanosleep.c @@ -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 #include "intprops.h" -#include "timespec.h" #ifndef TIME_T_MAX # define TIME_T_MAX TYPE_MAXIMUM (time_t) diff --git a/m4/nanosleep.m4 b/m4/nanosleep.m4 index d25295e38..af346b6cf 100644 --- a/m4/nanosleep.m4 +++ b/m4/nanosleep.m4 @@ -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 diff --git a/m4/strptime.m4 b/m4/strptime.m4 index e1236b933..5f919984d 100644 --- a/m4/strptime.m4 +++ b/m4/strptime.m4 @@ -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 index 000000000..e90ed7ac3 --- /dev/null +++ b/m4/time_h.m4 @@ -0,0 +1,76 @@ +# Configure a more-standard replacement for . + +# 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 ], + [gl_cv_sys_struct_timespec_in_time_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[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 ], + [gl_cv_sys_struct_timespec_in_sys_time_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[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]) +]) diff --git a/m4/time_r.m4 b/m4/time_r.m4 index ac8353a56..a4e016f81 100644 --- a/m4/time_r.m4 +++ b/m4/time_r.m4 @@ -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 diff --git a/m4/timegm.m4 b/m4/timegm.m4 index 82e9d66be..51ffd0fb1 100644 --- a/m4/timegm.m4 +++ b/m4/timegm.m4 @@ -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 ]) + fi + if test $REPLACE_TIMEGM = 1; then gl_PREREQ_TIMEGM fi - - AC_CHECK_DECLS([timegm], , , [#include ]) ]) # Prerequisites of lib/timegm.c. diff --git a/m4/timespec.m4 b/m4/timespec.m4 index 3305fd731..36f1238e8 100644 --- a/m4/timespec.m4 +++ b/m4/timespec.m4 @@ -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 to declare nanosleep. - AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - - AC_CHECK_DECLS(nanosleep, , , [#include ]) -]) - -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 - #endif - #include - ]], - [[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 . ]) - fi ]) diff --git a/modules/getdate b/modules/getdate index ae5584e50..653fd7a53 100644 --- a/modules/getdate +++ b/modules/getdate @@ -10,11 +10,11 @@ m4/tm_gmtoff.m4 m4/getdate.m4 Depends-on: -timespec stdbool gettime mktime setenv +time xalloc configure.ac: diff --git a/modules/nanosleep b/modules/nanosleep index 4cc7f527c..e7dfac413 100644 --- a/modules/nanosleep +++ b/modules/nanosleep @@ -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" + Link: $(LIB_NANOSLEEP) diff --git a/modules/stat-time b/modules/stat-time index 666f4ed04..13dc911cb 100644 --- a/modules/stat-time +++ b/modules/stat-time @@ -6,7 +6,7 @@ lib/stat-time.h m4/stat-time.m4 Depends-on: -timespec +time configure.ac: gl_STAT_TIME diff --git a/modules/strptime b/modules/strptime index 690c76241..799170a3a 100644 --- a/modules/strptime +++ b/modules/strptime @@ -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" + License: LGPL diff --git a/modules/time b/modules/time new file mode 100644 index 000000000..d93ee8df4 --- /dev/null +++ b/modules/time @@ -0,0 +1,42 @@ +Description: +A more-standard . + +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 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 + +License: +LGPL + +Maintainer: +all diff --git a/modules/time_r b/modules/time_r index 96df2f781..a0ec5cd00 100644 --- a/modules/time_r +++ b/modules/time_r @@ -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" + License: LGPL diff --git a/modules/timegm b/modules/timegm index b73d59a0c..a8bb54bc3 100644 --- a/modules/timegm +++ b/modules/timegm @@ -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" + License: LGPL diff --git a/modules/timespec b/modules/timespec index edd2dfc7b..8d74632c9 100644 --- a/modules/timespec +++ b/modules/timespec @@ -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 diff --git a/modules/utimecmp b/modules/utimecmp index a042393d7..12da25e9a 100644 --- a/modules/utimecmp +++ b/modules/utimecmp @@ -9,7 +9,7 @@ m4/utimecmp.m4 Depends-on: hash stat-time -timespec +time utimens xalloc intprops diff --git a/modules/utimens b/modules/utimens index c341f6577..caf8805d6 100644 --- a/modules/utimens +++ b/modules/utimens @@ -10,7 +10,7 @@ m4/utimes.m4 Depends-on: sys_time -timespec +time configure.ac: gl_UTIMENS diff --git a/modules/xnanosleep b/modules/xnanosleep index fa063cb76..b8c758cc0 100644 --- a/modules/xnanosleep +++ b/modules/xnanosleep @@ -8,7 +8,7 @@ m4/xnanosleep.m4 Depends-on: nanosleep -timespec +time intprops stdbool -- 2.11.0