Followup to the 2007-02-12 patch, using suggestions from Bruno Haible in
[gnulib.git] / lib / time_.h
1 /* A more-standard <time.h>.
2
3    Copyright (C) 2007 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 /* Don't get in the way of glibc when it includes time.h merely to
20    declare a few standard symbols, rather than to declare all the
21    symbols.  */
22 #if defined __need_time_t || defined __need_clock_t || defined __need_timespec
23 # include @ABSOLUTE_TIME_H@
24
25 #elif ! defined _GL_TIME_H
26 # define _GL_TIME_H
27 # include @ABSOLUTE_TIME_H@
28
29 # ifdef __cplusplus
30 extern "C" {
31 # endif
32
33 /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
34    Or they define it with the wrong member names or define it in <sys/time.h>
35    (e.g., FreeBSD circa 1997).  */
36 # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
37 #  if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
38 #   include <sys/time.h>
39 #  else
40 #   undef timespec
41 #   define timespec rpl_timespec
42 struct timespec
43 {
44   time_t tv_sec;
45   long int tv_nsec;
46 };
47 #  endif
48 # endif
49
50 /* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
51    return -1 and store the remaining time into RMTP.  See
52    <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
53 # if @REPLACE_NANOSLEEP@
54 #  define nanosleep rpl_nanosleep
55 int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp);
56 # endif
57
58 /* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
59    <http://www.opengroup.org/susv3xsh/localtime_r.html> and
60    <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
61 # if @REPLACE_LOCALTIME_R@
62 #  undef localtime_r
63 #  define localtime_r rpl_localtime_r
64 #  undef gmtime_r
65 #  define gmtime_r rpl_gmtime_r
66 struct tm *localtime_r (time_t const *restrict __timer,
67                         struct tm *restrict __result);
68 struct tm *gmtime_r (time_t const *restrict __timer,
69                      struct tm *restrict __result);
70 # endif
71
72 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
73    the resulting broken-down time into TM.  See
74    <http://www.opengroup.org/susv3xsh/strptime.html>.  */
75 # if @REPLACE_STRPTIME@
76 #  undef strptime
77 #  define strptime rpl_strptime
78 char *strptime (char const *restrict __buf, char const *restrict __format,
79                 struct tm *restrict __tm);
80 # endif
81
82 /* Convert TM to a time_t value, assuming UTC.  */
83 # if @REPLACE_TIMEGM@
84 #  undef timegm
85 #  define timegm rpl_timegm
86 time_t timegm (struct tm *__tm);
87 #endif
88
89 /* Encourage applications to avoid unsafe functions that can overrun
90    buffers when given outlandish struct tm values.  Portable
91    applications should use strftime (or even sprintf) instead.  */
92 # if GNULIB_PORTCHECK
93 #  undef asctime
94 #  define asctime eschew_asctime
95 #  undef asctime_r
96 #  define asctime_r eschew_asctime_r
97 #  undef ctime
98 #  define ctime eschew_ctime
99 #  undef ctime_r
100 #  define ctime_r eschew_ctime_r
101 # endif
102
103 # ifdef __cplusplus
104 }
105 # endif
106
107 #endif