* lib/fcntl_.h: Prefer #include_next <foo.h> to #include
[pspp] / 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
24 # if @HAVE_INCLUDE_NEXT@
25 #  include_next <time.h>
26 # else
27 #  include @ABSOLUTE_TIME_H@
28 # endif
29
30 #else
31 /* Normal invocation convention.  */
32
33 # if @HAVE_INCLUDE_NEXT@
34 #  include_next <time.h>
35 # endif
36
37 # if ! defined _GL_TIME_H
38 #  define _GL_TIME_H
39
40 #  if ! @HAVE_INCLUDE_NEXT@
41 #   include @ABSOLUTE_TIME_H@
42 #  endif
43
44 #  ifdef __cplusplus
45 extern "C" {
46 #  endif
47
48 /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
49    Or they define it with the wrong member names or define it in <sys/time.h>
50    (e.g., FreeBSD circa 1997).  */
51 #  if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
52 #   if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
53 #    include <sys/time.h>
54 #   else
55 #    undef timespec
56 #    define timespec rpl_timespec
57 struct timespec
58 {
59   time_t tv_sec;
60   long int tv_nsec;
61 };
62 #   endif
63 #  endif
64
65 /* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
66    return -1 and store the remaining time into RMTP.  See
67    <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
68 #  if @REPLACE_NANOSLEEP@
69 #   define nanosleep rpl_nanosleep
70 int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp);
71 #  endif
72
73 /* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
74    <http://www.opengroup.org/susv3xsh/localtime_r.html> and
75    <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
76 #  if @REPLACE_LOCALTIME_R@
77 #   undef localtime_r
78 #   define localtime_r rpl_localtime_r
79 #   undef gmtime_r
80 #   define gmtime_r rpl_gmtime_r
81 struct tm *localtime_r (time_t const *restrict __timer,
82                         struct tm *restrict __result);
83 struct tm *gmtime_r (time_t const *restrict __timer,
84                      struct tm *restrict __result);
85 #  endif
86
87 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
88    the resulting broken-down time into TM.  See
89    <http://www.opengroup.org/susv3xsh/strptime.html>.  */
90 #  if @REPLACE_STRPTIME@
91 #   undef strptime
92 #   define strptime rpl_strptime
93 char *strptime (char const *restrict __buf, char const *restrict __format,
94                 struct tm *restrict __tm);
95 #  endif
96
97 /* Convert TM to a time_t value, assuming UTC.  */
98 #  if @REPLACE_TIMEGM@
99 #   undef timegm
100 #   define timegm rpl_timegm
101 time_t timegm (struct tm *__tm);
102 #  endif
103
104 /* Encourage applications to avoid unsafe functions that can overrun
105    buffers when given outlandish struct tm values.  Portable
106    applications should use strftime (or even sprintf) instead.  */
107 #  if GNULIB_PORTCHECK
108 #   undef asctime
109 #   define asctime eschew_asctime
110 #   undef asctime_r
111 #   define asctime_r eschew_asctime_r
112 #   undef ctime
113 #   define ctime eschew_ctime
114 #   undef ctime_r
115 #   define ctime_r eschew_ctime_r
116 #  endif
117
118 #  ifdef __cplusplus
119 }
120 #  endif
121
122 # endif
123 #endif