diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2007-02-12 18:49:19 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2007-02-12 18:49:19 +0000 |
commit | 3ac9552429c5a500717e1d3d129c32f7d0ea37a3 (patch) | |
tree | d4fdd783d13d128eb9982d352264195f37acb429 /lib | |
parent | 4bc8b69ccf12c40ba0eec577b18e24bdd3cbc945 (diff) | |
download | gnulib-3ac9552429c5a500717e1d3d129c32f7d0ea37a3.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mktime.c | 8 | ||||
-rw-r--r-- | lib/nanosleep.c | 8 | ||||
-rw-r--r-- | lib/strftime.c | 3 | ||||
-rw-r--r-- | lib/strptime.c | 5 | ||||
-rw-r--r-- | lib/strptime.h | 30 | ||||
-rw-r--r-- | lib/time_.h | 107 | ||||
-rw-r--r-- | lib/time_r.c | 4 | ||||
-rw-r--r-- | lib/time_r.h | 52 | ||||
-rw-r--r-- | lib/timegm.c | 13 | ||||
-rw-r--r-- | lib/timegm.h | 23 | ||||
-rw-r--r-- | lib/timespec.h | 18 | ||||
-rw-r--r-- | lib/xnanosleep.c | 4 |
12 files changed, 127 insertions, 148 deletions
diff --git a/lib/mktime.c b/lib/mktime.c index ded3295c6f..a91fb20e68 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 <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 diff --git a/lib/nanosleep.c b/lib/nanosleep.c index bb47268123..89c5512428 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -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" @@ -36,12 +34,12 @@ #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 diff --git a/lib/strftime.c b/lib/strftime.c index 3fce99bd89..1c202c9b61 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 9373b45d7e..c5a039da95 100644 --- a/lib/strptime.c +++ b/lib/strptime.c @@ -17,9 +17,10 @@ #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 index 970574131f..0000000000 --- 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 <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 index 0000000000..7403270874 --- /dev/null +++ b/lib/time_.h @@ -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 diff --git a/lib/time_r.c b/lib/time_r.c index 3205862adf..2b72692844 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 <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 index ba8b0706b4..0000000000 --- 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 <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 diff --git a/lib/timegm.c b/lib/timegm.c index 656df1c954..67230cf34b 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 <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 index ee513f4e11..0000000000 --- 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 <time.h> - -#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 c65257792c..cce2d663ad 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 <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 *); diff --git a/lib/xnanosleep.c b/lib/xnanosleep.c index 70c7f2a37f..ebbd7ee89a 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 <time.h> #include "intprops.h" -#include "timespec.h" #ifndef TIME_T_MAX # define TIME_T_MAX TYPE_MAXIMUM (time_t) |