]> git.ipfire.org Git - thirdparty/glibc.git/blame - time/time.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / time / time.h
CommitLineData
6d7e8eda 1/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
ba1ffaa1 2 This file is part of the GNU C Library.
28f540f4 3
ba1ffaa1 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 8
ba1ffaa1
UD
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
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
28f540f4
RM
17
18/*
d1646309 19 * ISO C99 Standard: 7.23 Date and time <time.h>
28f540f4
RM
20 */
21
22#ifndef _TIME_H
05b68e14 23#define _TIME_H 1
28f540f4 24
05b68e14 25#include <features.h>
28f540f4 26
05b68e14
ZW
27#define __need_size_t
28#define __need_NULL
29#include <stddef.h>
28f540f4 30
f8cac037 31/* This defines CLOCKS_PER_SEC, which is the number of processor clock
05b68e14
ZW
32 ticks per second, and possibly a number of other constants. */
33#include <bits/time.h>
91bc38d0 34
05b68e14
ZW
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>
28f540f4 40
05b68e14
ZW
41#if defined __USE_POSIX199309 || defined __USE_ISOC11
42# include <bits/types/struct_timespec.h>
7a5affeb 43#endif
28f540f4 44
05b68e14
ZW
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>
252ff6b6 49struct sigevent;
05b68e14 50#endif
252ff6b6 51
05b68e14
ZW
52#ifdef __USE_XOPEN2K
53# ifndef __pid_t_defined
094f72c6 54typedef __pid_t pid_t;
05b68e14 55# define __pid_t_defined
74033a25 56# endif
05b68e14 57#endif
74033a25 58
05b68e14 59#ifdef __USE_XOPEN2K8
f0be25b6 60# include <bits/types/locale_t.h>
05b68e14 61#endif
74033a25 62
05b68e14 63#ifdef __USE_ISOC11
74033a25 64/* Time base values for timespec_get. */
7a270350 65# define TIME_UTC 1
05b68e14 66#endif
094f72c6 67
05b68e14 68__BEGIN_DECLS
be1dd949 69
28f540f4 70/* Time used by the program so far (user time + system time).
09e56b9e 71 The result / CLOCKS_PER_SEC is program time in seconds. */
c1422e5b 72extern clock_t clock (void) __THROW;
28f540f4 73
47f24c21 74#ifndef __USE_TIME_BITS64
28f540f4 75/* Return the current time and put it in *TIMER if TIMER is not NULL. */
c1422e5b 76extern time_t time (time_t *__timer) __THROW;
28f540f4
RM
77
78/* Return the difference between TIME1 and TIME0. */
c1422e5b
UD
79extern double difftime (time_t __time1, time_t __time0)
80 __THROW __attribute__ ((__const__));
28f540f4
RM
81
82/* Return the `time_t' representation of TP and normalize TP. */
c1422e5b 83extern time_t mktime (struct tm *__tp) __THROW;
47f24c21
AZ
84#else
85# ifdef __REDIRECT_NTH
86extern time_t __REDIRECT_NTH (time, (time_t *__timer), __time64);
87extern double __REDIRECT_NTH (difftime, (time_t __time1, time_t __time0),
88 __difftime64) __attribute__ ((__const__));
89extern time_t __REDIRECT_NTH (mktime, (struct tm *__tp), __mktime64);
90# else
91# define time __time64
92# define difftime __difftime64
93# define mktime __mktime64
94# endif
95#endif
28f540f4
RM
96
97/* Format TP into S according to FORMAT.
98 Write no more than MAXSIZE characters and return the number
99 of characters written, or 0 if it would exceed MAXSIZE. */
c1422e5b 100extern size_t strftime (char *__restrict __s, size_t __maxsize,
a784e502
UD
101 const char *__restrict __format,
102 const struct tm *__restrict __tp) __THROW;
f8adc70c 103
05b68e14 104#ifdef __USE_XOPEN
f8adc70c
RM
105/* Parse S according to FORMAT and store binary time information in TP.
106 The return value is a pointer to the first unparsed character in S. */
a784e502
UD
107extern char *strptime (const char *__restrict __s,
108 const char *__restrict __fmt, struct tm *__tp)
c1422e5b 109 __THROW;
05b68e14 110#endif
28f540f4 111
05b68e14 112#ifdef __USE_XOPEN2K8
c4d6f155
RM
113/* Similar to the two functions above but take the information from
114 the provided locale and not the global locale. */
c4d6f155 115
c4d6f155 116extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
a784e502
UD
117 const char *__restrict __format,
118 const struct tm *__restrict __tp,
af85385f 119 locale_t __loc) __THROW;
05b68e14 120#endif
c4d6f155 121
05b68e14 122#ifdef __USE_GNU
a784e502
UD
123extern char *strptime_l (const char *__restrict __s,
124 const char *__restrict __fmt, struct tm *__tp,
af85385f 125 locale_t __loc) __THROW;
05b68e14 126#endif
c4d6f155 127
28f540f4 128
47f24c21 129#ifndef __USE_TIME_BITS64
28f540f4
RM
130/* Return the `struct tm' representation of *TIMER
131 in Universal Coordinated Time (aka Greenwich Mean Time). */
a784e502 132extern struct tm *gmtime (const time_t *__timer) __THROW;
28f540f4
RM
133
134/* Return the `struct tm' representation
135 of *TIMER in the local timezone. */
a784e502 136extern struct tm *localtime (const time_t *__timer) __THROW;
28f540f4 137
47f24c21
AZ
138#else
139# ifdef __REDIRECT_NTH
140extern struct tm*__REDIRECT_NTH (gmtime, (const time_t *__timer), __gmtime64);
141extern struct tm *__REDIRECT_NTH (localtime, (const time_t *__timer),
142 __localtime64);
143# else
144# define gmtime __gmtime64
145# define localtime __localtime64
146# endif
147#endif
148
149
80a5f8b1 150#if defined __USE_POSIX || __GLIBC_USE (ISOC2X)
47f24c21 151# ifndef __USE_TIME_BITS64
c2216480
RM
152/* Return the `struct tm' representation of *TIMER in UTC,
153 using *TP to store the result. */
a784e502 154extern struct tm *gmtime_r (const time_t *__restrict __timer,
c1422e5b 155 struct tm *__restrict __tp) __THROW;
c2216480
RM
156
157/* Return the `struct tm' representation of *TIMER in local time,
158 using *TP to store the result. */
a784e502 159extern struct tm *localtime_r (const time_t *__restrict __timer,
c1422e5b 160 struct tm *__restrict __tp) __THROW;
47f24c21
AZ
161# else
162# ifdef __REDIRECT_NTH
163extern struct tm*__REDIRECT_NTH (gmtime_r, (const time_t *__restrict __timer,
164 struct tm *__restrict __tp),
165 __gmtime64_r);
166
167extern struct tm*__REDIRECT_NTH (localtime_r, (const time_t *__restrict __t,
168 struct tm *__restrict __tp),
169 __localtime64_r);
170# else
171# define gmtime_r __gmtime64_r
172# define localtime_r __localtime_r
173# endif
174# endif
80a5f8b1 175#endif /* POSIX || C2X */
c2216480 176
28f540f4
RM
177/* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
178 that is the representation of TP in this format. */
a784e502 179extern char *asctime (const struct tm *__tp) __THROW;
28f540f4 180
f0f1bf85 181/* Equivalent to `asctime (localtime (timer))'. */
47f24c21 182#ifndef __USE_TIME_BITS64
a784e502 183extern char *ctime (const time_t *__timer) __THROW;
47f24c21
AZ
184#else
185# ifdef __REDIRECT_NTH
186extern char *__REDIRECT_NTH (ctime, (const time_t *__timer), __ctime64);
187# else
188# define ctime __ctime64
189# endif
190#endif
28f540f4 191
8382f4c3 192#ifdef __USE_POSIX
23396375
UD
193/* Reentrant versions of the above functions. */
194
195/* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
196 that is the representation of TP in this format. */
a784e502 197extern char *asctime_r (const struct tm *__restrict __tp,
c1422e5b 198 char *__restrict __buf) __THROW;
23396375 199
f0f1bf85 200/* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */
47f24c21 201#ifndef __USE_TIME_BITS64
a784e502 202extern char *ctime_r (const time_t *__restrict __timer,
c1422e5b 203 char *__restrict __buf) __THROW;
47f24c21
AZ
204#else
205# ifdef __REDIRECT_NTH
206extern char *__REDIRECT_NTH (ctime_r, (const time_t *__restrict __timer,
207 char *__restrict __buf), __ctime64_r);
208# else
209# define ctime_r __ctime64_r
210# endif
211#endif
212
8382f4c3 213#endif /* POSIX */
23396375 214
28f540f4
RM
215
216/* Defined in localtime.c. */
217extern char *__tzname[2]; /* Current timezone names. */
f0f1bf85 218extern int __daylight; /* If daylight-saving time is ever in use. */
28f540f4
RM
219extern long int __timezone; /* Seconds west of UTC. */
220
28f540f4 221
05b68e14 222#ifdef __USE_POSIX
28f540f4
RM
223/* Same as above. */
224extern char *tzname[2];
225
bdbf022d
UD
226/* Set time conversion information from the TZ environment variable.
227 If TZ is not defined, a locale-dependent default is used. */
c1422e5b 228extern void tzset (void) __THROW;
05b68e14 229#endif
28f540f4 230
05b68e14 231#if defined __USE_MISC || defined __USE_XOPEN
28f540f4
RM
232extern int daylight;
233extern long int timezone;
05b68e14 234#endif
28f540f4 235
28f540f4
RM
236
237/* Nonzero if YEAR is a leap year (every 4 years,
238 except every 100th isn't, and every 400th is). */
05b68e14 239#define __isleap(year) \
28f540f4
RM
240 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
241
242
828c7251
JM
243#if defined __USE_MISC || __GLIBC_USE (ISOC2X)
244# ifndef __USE_TIME_BITS64
245/* Like `mktime', but for TP represents Universal Time, not local time. */
246extern time_t timegm (struct tm *__tp) __THROW;
247# else
248# ifdef __REDIRECT_NTH
249extern time_t __REDIRECT_NTH (timegm, (struct tm *__tp), __timegm64);
250# else
251# define timegm __timegm64
252# endif
253# endif
254#endif
255
256
05b68e14 257#ifdef __USE_MISC
28f540f4
RM
258/* Miscellaneous functions many Unices inherited from the public domain
259 localtime package. These are included only for compatibility. */
260
47f24c21 261#ifndef __USE_TIME_BITS64
28f540f4 262/* Another name for `mktime'. */
c1422e5b 263extern time_t timelocal (struct tm *__tp) __THROW;
47f24c21
AZ
264#else
265# ifdef __REDIRECT_NTH
47f24c21 266extern time_t __REDIRECT_NTH (timelocal, (struct tm *__tp), __mktime64);
47f24c21
AZ
267# endif
268#endif
28f540f4
RM
269
270/* Return the number of days in YEAR. */
be2623ae 271extern int dysize (int __year) __THROW __attribute__ ((__const__));
05b68e14 272#endif
28f540f4
RM
273
274
05b68e14 275#ifdef __USE_POSIX199309
47f24c21 276# ifndef __USE_TIME_BITS64
2c008571
UD
277/* Pause execution for a number of nanoseconds.
278
279 This function is a cancellation point and therefore not marked with
280 __THROW. */
a784e502 281extern int nanosleep (const struct timespec *__requested_time,
2c008571 282 struct timespec *__remaining);
be1dd949 283
be1dd949 284/* Get resolution of clock CLOCK_ID. */
c1422e5b 285extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
be1dd949
UD
286
287/* Get current value of clock CLOCK_ID and store it in TP. */
cf73acb5
XN
288extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp)
289 __THROW __nonnull((2));
be1dd949
UD
290
291/* Set clock CLOCK_ID to value TP. */
a784e502 292extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
cf73acb5 293 __THROW __nonnull((2));
47f24c21
AZ
294# else
295# ifdef __REDIRECT
296extern int __REDIRECT (nanosleep, (const struct timespec *__requested_time,
297 struct timespec *__remaining),
298 __nanosleep64);
299extern int __REDIRECT_NTH (clock_getres, (clockid_t __clock_id,
300 struct timespec *__res),
301 __clock_getres64);
302extern int __REDIRECT_NTH (clock_gettime, (clockid_t __clock_id, struct
cf73acb5
XN
303 timespec *__tp), __clock_gettime64)
304 __nonnull((2));
47f24c21 305extern int __REDIRECT_NTH (clock_settime, (clockid_t __clock_id, const struct
cf73acb5
XN
306 timespec *__tp), __clock_settime64)
307 __nonnull((2));
47f24c21
AZ
308# else
309# define nanosleep __nanosleep64
310# define clock_getres __clock_getres64
311# define clock_gettime __clock_gettime64
312# define clock_settime __clock_settime64
313# endif
314# endif
315
be1dd949 316
05b68e14 317# ifdef __USE_XOPEN2K
2c008571
UD
318/* High-resolution sleep with the specified clock.
319
320 This function is a cancellation point and therefore not marked with
321 __THROW. */
47f24c21 322# ifndef __USE_TIME_BITS64
c000cdad 323extern int clock_nanosleep (clockid_t __clock_id, int __flags,
a784e502 324 const struct timespec *__req,
2c008571 325 struct timespec *__rem);
47f24c21
AZ
326# else
327# ifdef __REDIRECT
328extern int __REDIRECT (clock_nanosleep, (clockid_t __clock_id, int __flags,
329 const struct timespec *__req,
330 struct timespec *__rem),
331 __clock_nanosleep_time64);
332# else
333# define clock_nanosleep __clock_nanosleep_time64
334# endif
335# endif
c000cdad 336
094f72c6 337/* Return clock ID for CPU-time clock. */
77741499 338extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW;
05b68e14 339# endif
094f72c6 340
be1dd949
UD
341
342/* Create new per-process timer using CLOCK_ID. */
98cbe360
UD
343extern int timer_create (clockid_t __clock_id,
344 struct sigevent *__restrict __evp,
345 timer_t *__restrict __timerid) __THROW;
be1dd949
UD
346
347/* Delete timer TIMERID. */
c1422e5b 348extern int timer_delete (timer_t __timerid) __THROW;
be1dd949 349
1f529f7d 350/* Set timer TIMERID to VALUE, returning old value in OVALUE. */
47f24c21 351# ifndef __USE_TIME_BITS64
c1422e5b 352extern int timer_settime (timer_t __timerid, int __flags,
a784e502 353 const struct itimerspec *__restrict __value,
98cbe360 354 struct itimerspec *__restrict __ovalue) __THROW;
be1dd949 355
1f529f7d 356/* Get current value of timer TIMERID and store it in VALUE. */
c1422e5b
UD
357extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
358 __THROW;
47f24c21
AZ
359# else
360# ifdef __REDIRECT_NTH
361extern int __REDIRECT_NTH (timer_settime, (timer_t __timerid, int __flags,
362 const struct itimerspec *__restrict __value,
363 struct itimerspec *__restrict __ovalue),
364 __timer_settime64);
365
366extern int __REDIRECT_NTH (timer_gettime, (timer_t __timerid,
367 struct itimerspec *__value),
368 __timer_gettime64);
369# else
370# define timer_settime __timer_settime64
371# define timer_gettime __timer_gettime64
372# endif
373# endif
be1dd949
UD
374
375/* Get expiration overrun for timer TIMERID. */
c1422e5b 376extern int timer_getoverrun (timer_t __timerid) __THROW;
05b68e14 377#endif
7b3547eb
RM
378
379
05b68e14 380#ifdef __USE_ISOC11
47f24c21 381# ifndef __USE_TIME_BITS64
7a270350
UD
382/* Set TS to calendar time based in time base BASE. */
383extern int timespec_get (struct timespec *__ts, int __base)
384 __THROW __nonnull ((1));
47f24c21
AZ
385# else
386# ifdef __REDIRECT_NTH
387extern int __REDIRECT_NTH (timespec_get, (struct timespec *__ts, int __base),
388 __timespec_get64) __nonnull ((1));
389# else
390# define timespec_get __timespec_get64
391# endif
392# endif
05b68e14 393#endif
7a270350
UD
394
395
e5ac7bd6 396#if __GLIBC_USE (ISOC2X)
47f24c21 397# ifndef __USE_TIME_BITS64
e5ac7bd6
JM
398/* Set TS to resolution of time base BASE. */
399extern int timespec_getres (struct timespec *__ts, int __base)
400 __THROW;
47f24c21
AZ
401# else
402# ifdef __REDIRECT_NTH
403extern int __REDIRECT_NTH (timespec_getres, (struct timespec *__ts,
404 int __base),
405 __timespec_getres64);
406# else
407# define timespec_getres __timespec_getres64
408# endif
409# endif
e5ac7bd6
JM
410#endif
411
412
05b68e14 413#ifdef __USE_XOPEN_EXTENDED
f21acc89
UD
414/* Set to one of the following values to indicate an error.
415 1 the DATEMSK environment variable is null or undefined,
416 2 the template file cannot be opened for reading,
417 3 failed to get file status information,
418 4 the template file is not a regular file,
419 5 an error is encountered while reading the template file,
420 6 memory allication failed (not enough memory available),
421 7 there is no line in the template that matches the input,
422 8 invalid input specification Example: February 31 or a time is
4c1423ed 423 specified that can not be represented in a time_t (representing
f21acc89
UD
424 the time in seconds since 00:00:00 UTC, January 1, 1970) */
425extern int getdate_err;
426
427/* Parse the given string as a date specification and return a value
428 representing the value. The templates from the file identified by
429 the environment variable DATEMSK are used. In case of an error
2c008571
UD
430 `getdate_err' is set.
431
4c1423ed 432 This function is a possible cancellation point and therefore not
2c008571 433 marked with __THROW. */
a784e502 434extern struct tm *getdate (const char *__string);
05b68e14 435#endif
f21acc89 436
05b68e14 437#ifdef __USE_GNU
f21acc89
UD
438/* Since `getdate' is not reentrant because of the use of `getdate_err'
439 and the static buffer to return the result in, we provide a thread-safe
440 variant. The functionality is the same. The result is returned in
441 the buffer pointed to by RESBUFP and in case of an error the return
2c008571
UD
442 value is != 0 with the same values as given above for `getdate_err'.
443
444 This function is not part of POSIX and therefore no official
445 cancellation point. But due to similarity with an POSIX interface
446 or due to the implementation it is a cancellation point and
447 therefore not marked with __THROW. */
a784e502 448extern int getdate_r (const char *__restrict __string,
2c008571 449 struct tm *__restrict __resbufp);
05b68e14 450#endif
f21acc89 451
28f540f4
RM
452__END_DECLS
453
05b68e14 454#endif /* time.h. */