Update copyright dates not handled by scripts/update-copyrights.
[glibc.git] / time / time.h
blob7f98338abe4e0a42bf91b853d1d6d244fc812174
1 /* Copyright (C) 1991-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
19 * ISO C99 Standard: 7.23 Date and time <time.h>
22 #ifndef _TIME_H
23 #define _TIME_H 1
25 #include <features.h>
27 #define __need_size_t
28 #define __need_NULL
29 #include <stddef.h>
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>
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>
41 #if defined __USE_POSIX199309 || defined __USE_ISOC11
42 # include <bits/types/struct_timespec.h>
43 #endif
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>
49 struct sigevent;
50 #endif
52 #ifdef __USE_XOPEN2K
53 # ifndef __pid_t_defined
54 typedef __pid_t pid_t;
55 # define __pid_t_defined
56 # endif
57 #endif
59 #ifdef __USE_XOPEN2K8
60 # include <xlocale.h>
61 #endif
63 #ifdef __USE_ISOC11
64 /* Time base values for timespec_get. */
65 # define TIME_UTC 1
66 #endif
68 __BEGIN_DECLS
70 __BEGIN_NAMESPACE_STD
71 /* Time used by the program so far (user time + system time).
72 The result / CLOCKS_PER_SECOND is program time in seconds. */
73 extern clock_t clock (void) __THROW;
75 /* Return the current time and put it in *TIMER if TIMER is not NULL. */
76 extern time_t time (time_t *__timer) __THROW;
78 /* Return the difference between TIME1 and TIME0. */
79 extern double difftime (time_t __time1, time_t __time0)
80 __THROW __attribute__ ((__const__));
82 /* Return the `time_t' representation of TP and normalize TP. */
83 extern time_t mktime (struct tm *__tp) __THROW;
86 /* Format TP into S according to FORMAT.
87 Write no more than MAXSIZE characters and return the number
88 of characters written, or 0 if it would exceed MAXSIZE. */
89 extern size_t strftime (char *__restrict __s, size_t __maxsize,
90 const char *__restrict __format,
91 const struct tm *__restrict __tp) __THROW;
92 __END_NAMESPACE_STD
94 #ifdef __USE_XOPEN
95 /* Parse S according to FORMAT and store binary time information in TP.
96 The return value is a pointer to the first unparsed character in S. */
97 extern char *strptime (const char *__restrict __s,
98 const char *__restrict __fmt, struct tm *__tp)
99 __THROW;
100 #endif
102 #ifdef __USE_XOPEN2K8
103 /* Similar to the two functions above but take the information from
104 the provided locale and not the global locale. */
106 extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
107 const char *__restrict __format,
108 const struct tm *__restrict __tp,
109 __locale_t __loc) __THROW;
110 #endif
112 #ifdef __USE_GNU
113 extern char *strptime_l (const char *__restrict __s,
114 const char *__restrict __fmt, struct tm *__tp,
115 __locale_t __loc) __THROW;
116 #endif
119 __BEGIN_NAMESPACE_STD
120 /* Return the `struct tm' representation of *TIMER
121 in Universal Coordinated Time (aka Greenwich Mean Time). */
122 extern struct tm *gmtime (const time_t *__timer) __THROW;
124 /* Return the `struct tm' representation
125 of *TIMER in the local timezone. */
126 extern struct tm *localtime (const time_t *__timer) __THROW;
127 __END_NAMESPACE_STD
129 #ifdef __USE_POSIX
130 /* Return the `struct tm' representation of *TIMER in UTC,
131 using *TP to store the result. */
132 extern struct tm *gmtime_r (const time_t *__restrict __timer,
133 struct tm *__restrict __tp) __THROW;
135 /* Return the `struct tm' representation of *TIMER in local time,
136 using *TP to store the result. */
137 extern struct tm *localtime_r (const time_t *__restrict __timer,
138 struct tm *__restrict __tp) __THROW;
139 #endif /* POSIX */
141 __BEGIN_NAMESPACE_STD
142 /* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
143 that is the representation of TP in this format. */
144 extern char *asctime (const struct tm *__tp) __THROW;
146 /* Equivalent to `asctime (localtime (timer))'. */
147 extern char *ctime (const time_t *__timer) __THROW;
148 __END_NAMESPACE_STD
150 #ifdef __USE_POSIX
151 /* Reentrant versions of the above functions. */
153 /* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
154 that is the representation of TP in this format. */
155 extern char *asctime_r (const struct tm *__restrict __tp,
156 char *__restrict __buf) __THROW;
158 /* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */
159 extern char *ctime_r (const time_t *__restrict __timer,
160 char *__restrict __buf) __THROW;
161 #endif /* POSIX */
164 /* Defined in localtime.c. */
165 extern char *__tzname[2]; /* Current timezone names. */
166 extern int __daylight; /* If daylight-saving time is ever in use. */
167 extern long int __timezone; /* Seconds west of UTC. */
170 #ifdef __USE_POSIX
171 /* Same as above. */
172 extern char *tzname[2];
174 /* Set time conversion information from the TZ environment variable.
175 If TZ is not defined, a locale-dependent default is used. */
176 extern void tzset (void) __THROW;
177 #endif
179 #if defined __USE_MISC || defined __USE_XOPEN
180 extern int daylight;
181 extern long int timezone;
182 #endif
184 #ifdef __USE_MISC
185 /* Set the system time to *WHEN.
186 This call is restricted to the superuser. */
187 extern int stime (const time_t *__when) __THROW;
188 #endif
191 /* Nonzero if YEAR is a leap year (every 4 years,
192 except every 100th isn't, and every 400th is). */
193 #define __isleap(year) \
194 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
197 #ifdef __USE_MISC
198 /* Miscellaneous functions many Unices inherited from the public domain
199 localtime package. These are included only for compatibility. */
201 /* Like `mktime', but for TP represents Universal Time, not local time. */
202 extern time_t timegm (struct tm *__tp) __THROW;
204 /* Another name for `mktime'. */
205 extern time_t timelocal (struct tm *__tp) __THROW;
207 /* Return the number of days in YEAR. */
208 extern int dysize (int __year) __THROW __attribute__ ((__const__));
209 #endif
212 #ifdef __USE_POSIX199309
213 /* Pause execution for a number of nanoseconds.
215 This function is a cancellation point and therefore not marked with
216 __THROW. */
217 extern int nanosleep (const struct timespec *__requested_time,
218 struct timespec *__remaining);
221 /* Get resolution of clock CLOCK_ID. */
222 extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
224 /* Get current value of clock CLOCK_ID and store it in TP. */
225 extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
227 /* Set clock CLOCK_ID to value TP. */
228 extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
229 __THROW;
231 # ifdef __USE_XOPEN2K
232 /* High-resolution sleep with the specified clock.
234 This function is a cancellation point and therefore not marked with
235 __THROW. */
236 extern int clock_nanosleep (clockid_t __clock_id, int __flags,
237 const struct timespec *__req,
238 struct timespec *__rem);
240 /* Return clock ID for CPU-time clock. */
241 extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW;
242 # endif
245 /* Create new per-process timer using CLOCK_ID. */
246 extern int timer_create (clockid_t __clock_id,
247 struct sigevent *__restrict __evp,
248 timer_t *__restrict __timerid) __THROW;
250 /* Delete timer TIMERID. */
251 extern int timer_delete (timer_t __timerid) __THROW;
253 /* Set timer TIMERID to VALUE, returning old value in OVALUE. */
254 extern int timer_settime (timer_t __timerid, int __flags,
255 const struct itimerspec *__restrict __value,
256 struct itimerspec *__restrict __ovalue) __THROW;
258 /* Get current value of timer TIMERID and store it in VALUE. */
259 extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
260 __THROW;
262 /* Get expiration overrun for timer TIMERID. */
263 extern int timer_getoverrun (timer_t __timerid) __THROW;
264 #endif
267 #ifdef __USE_ISOC11
268 /* Set TS to calendar time based in time base BASE. */
269 extern int timespec_get (struct timespec *__ts, int __base)
270 __THROW __nonnull ((1));
271 #endif
274 #ifdef __USE_XOPEN_EXTENDED
275 /* Set to one of the following values to indicate an error.
276 1 the DATEMSK environment variable is null or undefined,
277 2 the template file cannot be opened for reading,
278 3 failed to get file status information,
279 4 the template file is not a regular file,
280 5 an error is encountered while reading the template file,
281 6 memory allication failed (not enough memory available),
282 7 there is no line in the template that matches the input,
283 8 invalid input specification Example: February 31 or a time is
284 specified that can not be represented in a time_t (representing
285 the time in seconds since 00:00:00 UTC, January 1, 1970) */
286 extern int getdate_err;
288 /* Parse the given string as a date specification and return a value
289 representing the value. The templates from the file identified by
290 the environment variable DATEMSK are used. In case of an error
291 `getdate_err' is set.
293 This function is a possible cancellation point and therefore not
294 marked with __THROW. */
295 extern struct tm *getdate (const char *__string);
296 #endif
298 #ifdef __USE_GNU
299 /* Since `getdate' is not reentrant because of the use of `getdate_err'
300 and the static buffer to return the result in, we provide a thread-safe
301 variant. The functionality is the same. The result is returned in
302 the buffer pointed to by RESBUFP and in case of an error the return
303 value is != 0 with the same values as given above for `getdate_err'.
305 This function is not part of POSIX and therefore no official
306 cancellation point. But due to similarity with an POSIX interface
307 or due to the implementation it is a cancellation point and
308 therefore not marked with __THROW. */
309 extern int getdate_r (const char *__restrict __string,
310 struct tm *__restrict __resbufp);
311 #endif
313 __END_DECLS
315 #endif /* time.h. */