1/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18/*
19 * ISO C99 Standard: 7.23 Date and time <time.h>
20 */
21
22#ifndef _TIME_H
23#define _TIME_H 1
24
25#include <features.h>
26
27#define __need_size_t
28#define __need_NULL
29#include <stddef.h>
30
31/* This defines CLOCKS_PER_SEC, which is the number of processor clock
32 ticks per second, and possibly a number of other constants. */
33#include <bits/time.h>
34
35/* Many of the typedefs and structs whose official home is this header
36 may also need to be defined by other headers. */
37#include <bits/types/clock_t.h>
38#include <bits/types/time_t.h>
39#include <bits/types/struct_tm.h>
40
41#if defined __USE_POSIX199309 || defined __USE_ISOC11
42# include <bits/types/struct_timespec.h>
43#endif
44
45#ifdef __USE_POSIX199309
46# include <bits/types/clockid_t.h>
47# include <bits/types/timer_t.h>
48# include <bits/types/struct_itimerspec.h>
49struct sigevent;
50#endif
51
52#ifdef __USE_XOPEN2K
53# ifndef __pid_t_defined
54typedef __pid_t pid_t;
55# define __pid_t_defined
56# endif
57#endif
58
59#ifdef __USE_XOPEN2K8
60# include <bits/types/locale_t.h>
61#endif
62
63#ifdef __USE_ISOC11
64/* Time base values for timespec_get. */
65# define TIME_UTC 1
66#endif
67
68__BEGIN_DECLS
69
70/* Time used by the program so far (user time + system time).
71 The result / CLOCKS_PER_SEC is program time in seconds. */
72extern clock_t clock (void) __THROW;
73
74/* Return the current time and put it in *TIMER if TIMER is not NULL. */
75extern time_t time (time_t *__timer) __THROW;
76
77/* Return the difference between TIME1 and TIME0. */
78extern double difftime (time_t __time1, time_t __time0)
79 __THROW __attribute__ ((__const__));
80
81/* Return the `time_t' representation of TP and normalize TP. */
82extern time_t mktime (struct tm *__tp) __THROW;
83
84
85/* Format TP into S according to FORMAT.
86 Write no more than MAXSIZE characters and return the number
87 of characters written, or 0 if it would exceed MAXSIZE. */
88extern size_t strftime (char *__restrict __s, size_t __maxsize,
89 const char *__restrict __format,
90 const struct tm *__restrict __tp) __THROW;
91
92#ifdef __USE_XOPEN
93/* Parse S according to FORMAT and store binary time information in TP.
94 The return value is a pointer to the first unparsed character in S. */
95extern char *strptime (const char *__restrict __s,
96 const char *__restrict __fmt, struct tm *__tp)
97 __THROW;
98#endif
99
100#ifdef __USE_XOPEN2K8
101/* Similar to the two functions above but take the information from
102 the provided locale and not the global locale. */
103
104extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
105 const char *__restrict __format,
106 const struct tm *__restrict __tp,
107 locale_t __loc) __THROW;
108#endif
109
110#ifdef __USE_GNU
111extern char *strptime_l (const char *__restrict __s,
112 const char *__restrict __fmt, struct tm *__tp,
113 locale_t __loc) __THROW;
114#endif
115
116
117/* Return the `struct tm' representation of *TIMER
118 in Universal Coordinated Time (aka Greenwich Mean Time). */
119extern struct tm *gmtime (const time_t *__timer) __THROW;
120
121/* Return the `struct tm' representation
122 of *TIMER in the local timezone. */
123extern struct tm *localtime (const time_t *__timer) __THROW;
124
125#ifdef __USE_POSIX
126/* Return the `struct tm' representation of *TIMER in UTC,
127 using *TP to store the result. */
128extern struct tm *gmtime_r (const time_t *__restrict __timer,
129 struct tm *__restrict __tp) __THROW;
130
131/* Return the `struct tm' representation of *TIMER in local time,
132 using *TP to store the result. */
133extern struct tm *localtime_r (const time_t *__restrict __timer,
134 struct tm *__restrict __tp) __THROW;
135#endif /* POSIX */
136
137/* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
138 that is the representation of TP in this format. */
139extern char *asctime (const struct tm *__tp) __THROW;
140
141/* Equivalent to `asctime (localtime (timer))'. */
142extern char *ctime (const time_t *__timer) __THROW;
143
144#ifdef __USE_POSIX
145/* Reentrant versions of the above functions. */
146
147/* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
148 that is the representation of TP in this format. */
149extern char *asctime_r (const struct tm *__restrict __tp,
150 char *__restrict __buf) __THROW;
151
152/* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */
153extern char *ctime_r (const time_t *__restrict __timer,
154 char *__restrict __buf) __THROW;
155#endif /* POSIX */
156
157
158/* Defined in localtime.c. */
159extern char *__tzname[2]; /* Current timezone names. */
160extern int __daylight; /* If daylight-saving time is ever in use. */
161extern long int __timezone; /* Seconds west of UTC. */
162
163
164#ifdef __USE_POSIX
165/* Same as above. */
166extern char *tzname[2];
167
168/* Set time conversion information from the TZ environment variable.
169 If TZ is not defined, a locale-dependent default is used. */
170extern void tzset (void) __THROW;
171#endif
172
173#if defined __USE_MISC || defined __USE_XOPEN
174extern int daylight;
175extern long int timezone;
176#endif
177
178#ifdef __USE_MISC
179/* Set the system time to *WHEN.
180 This call is restricted to the superuser. */
181extern int stime (const time_t *__when) __THROW;
182#endif
183
184
185/* Nonzero if YEAR is a leap year (every 4 years,
186 except every 100th isn't, and every 400th is). */
187#define __isleap(year) \
188 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
189
190
191#ifdef __USE_MISC
192/* Miscellaneous functions many Unices inherited from the public domain
193 localtime package. These are included only for compatibility. */
194
195/* Like `mktime', but for TP represents Universal Time, not local time. */
196extern time_t timegm (struct tm *__tp) __THROW;
197
198/* Another name for `mktime'. */
199extern time_t timelocal (struct tm *__tp) __THROW;
200
201/* Return the number of days in YEAR. */
202extern int dysize (int __year) __THROW __attribute__ ((__const__));
203#endif
204
205
206#ifdef __USE_POSIX199309
207/* Pause execution for a number of nanoseconds.
208
209 This function is a cancellation point and therefore not marked with
210 __THROW. */
211extern int nanosleep (const struct timespec *__requested_time,
212 struct timespec *__remaining);
213
214
215/* Get resolution of clock CLOCK_ID. */
216extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
217
218/* Get current value of clock CLOCK_ID and store it in TP. */
219extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
220
221/* Set clock CLOCK_ID to value TP. */
222extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
223 __THROW;
224
225# ifdef __USE_XOPEN2K
226/* High-resolution sleep with the specified clock.
227
228 This function is a cancellation point and therefore not marked with
229 __THROW. */
230extern int clock_nanosleep (clockid_t __clock_id, int __flags,
231 const struct timespec *__req,
232 struct timespec *__rem);
233
234/* Return clock ID for CPU-time clock. */
235extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW;
236# endif
237
238
239/* Create new per-process timer using CLOCK_ID. */
240extern int timer_create (clockid_t __clock_id,
241 struct sigevent *__restrict __evp,
242 timer_t *__restrict __timerid) __THROW;
243
244/* Delete timer TIMERID. */
245extern int timer_delete (timer_t __timerid) __THROW;
246
247/* Set timer TIMERID to VALUE, returning old value in OVALUE. */
248extern int timer_settime (timer_t __timerid, int __flags,
249 const struct itimerspec *__restrict __value,
250 struct itimerspec *__restrict __ovalue) __THROW;
251
252/* Get current value of timer TIMERID and store it in VALUE. */
253extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
254 __THROW;
255
256/* Get expiration overrun for timer TIMERID. */
257extern int timer_getoverrun (timer_t __timerid) __THROW;
258#endif
259
260
261#ifdef __USE_ISOC11
262/* Set TS to calendar time based in time base BASE. */
263extern int timespec_get (struct timespec *__ts, int __base)
264 __THROW __nonnull ((1));
265#endif
266
267
268#ifdef __USE_XOPEN_EXTENDED
269/* Set to one of the following values to indicate an error.
270 1 the DATEMSK environment variable is null or undefined,
271 2 the template file cannot be opened for reading,
272 3 failed to get file status information,
273 4 the template file is not a regular file,
274 5 an error is encountered while reading the template file,
275 6 memory allication failed (not enough memory available),
276 7 there is no line in the template that matches the input,
277 8 invalid input specification Example: February 31 or a time is
278 specified that can not be represented in a time_t (representing
279 the time in seconds since 00:00:00 UTC, January 1, 1970) */
280extern int getdate_err;
281
282/* Parse the given string as a date specification and return a value
283 representing the value. The templates from the file identified by
284 the environment variable DATEMSK are used. In case of an error
285 `getdate_err' is set.
286
287 This function is a possible cancellation point and therefore not
288 marked with __THROW. */
289extern struct tm *getdate (const char *__string);
290#endif
291
292#ifdef __USE_GNU
293/* Since `getdate' is not reentrant because of the use of `getdate_err'
294 and the static buffer to return the result in, we provide a thread-safe
295 variant. The functionality is the same. The result is returned in
296 the buffer pointed to by RESBUFP and in case of an error the return
297 value is != 0 with the same values as given above for `getdate_err'.
298
299 This function is not part of POSIX and therefore no official
300 cancellation point. But due to similarity with an POSIX interface
301 or due to the implementation it is a cancellation point and
302 therefore not marked with __THROW. */
303extern int getdate_r (const char *__restrict __string,
304 struct tm *__restrict __resbufp);
305#endif
306
307__END_DECLS
308
309#endif /* time.h. */
310