]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/include/time.h
Don't define `_POSIX_THREADS` unless threads are enabled. (#356)
[wasi-libc.git] / libc-top-half / musl / include / time.h
CommitLineData
320054e8
DG
1#ifndef _TIME_H
2#define _TIME_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <features.h>
9
e5f14be3 10#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
5d8a1409
DG
11#if __cplusplus >= 201103L
12#define NULL nullptr
13#elif defined(__cplusplus)
320054e8
DG
14#define NULL 0L
15#else
16#define NULL ((void*)0)
17#endif
18#else
19#define __need_NULL
20#include <stddef.h>
21#endif
22
23
24#define __NEED_size_t
25#define __NEED_time_t
26#define __NEED_clock_t
27#define __NEED_struct_timespec
28
29#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
30 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
31 || defined(_BSD_SOURCE)
32#define __NEED_clockid_t
33#define __NEED_timer_t
34#define __NEED_pid_t
35#define __NEED_locale_t
36#endif
37
38#include <bits/alltypes.h>
39
40#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
41#define __tm_gmtoff tm_gmtoff
42#define __tm_zone tm_zone
43#endif
44
e5f14be3 45#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
320054e8
DG
46struct tm {
47 int tm_sec;
48 int tm_min;
49 int tm_hour;
50 int tm_mday;
51 int tm_mon;
52 int tm_year;
53 int tm_wday;
54 int tm_yday;
55 int tm_isdst;
56 long __tm_gmtoff;
57 const char *__tm_zone;
58};
59#else
60#include <__header_time.h>
61#endif
62
b9b64a69 63#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS)
320054e8 64clock_t clock (void);
b9b64a69
DG
65#else
66__attribute__((__deprecated__(
67"WASI lacks process-associated clocks; to enable emulation of the `clock` function using "
68"the wall clock, which isn't sensitive to whether the program is running or suspended, "
69"compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks"
70)))
71clock_t clock (void);
72#endif
320054e8
DG
73time_t time (time_t *);
74double difftime (time_t, time_t);
75time_t mktime (struct tm *);
76size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict);
77struct tm *gmtime (const time_t *);
78struct tm *localtime (const time_t *);
79char *asctime (const struct tm *);
80char *ctime (const time_t *);
81int timespec_get(struct timespec *, int);
82
e5f14be3 83#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
320054e8
DG
84#define CLOCKS_PER_SEC 1000000L
85
86#define TIME_UTC 1
87#endif
88
89#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
90 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
91 || defined(_BSD_SOURCE)
92
93size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t);
94
95struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
96struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
97char *asctime_r (const struct tm *__restrict, char *__restrict);
98char *ctime_r (const time_t *, char *);
99
24f6fe1c 100#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */
320054e8 101void tzset (void);
24f6fe1c 102#endif
320054e8
DG
103
104struct itimerspec {
105 struct timespec it_interval;
106 struct timespec it_value;
107};
108
e5f14be3 109#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
320054e8
DG
110#define CLOCK_REALTIME 0
111#define CLOCK_MONOTONIC 1
112#define CLOCK_PROCESS_CPUTIME_ID 2
113#define CLOCK_THREAD_CPUTIME_ID 3
114#define CLOCK_MONOTONIC_RAW 4
115#define CLOCK_REALTIME_COARSE 5
116#define CLOCK_MONOTONIC_COARSE 6
117#define CLOCK_BOOTTIME 7
118#define CLOCK_REALTIME_ALARM 8
119#define CLOCK_BOOTTIME_ALARM 9
120#define CLOCK_SGI_CYCLE 10
121#define CLOCK_TAI 11
122
123#define TIMER_ABSTIME 1
124#endif
125
126int nanosleep (const struct timespec *, struct timespec *);
127int clock_getres (clockid_t, struct timespec *);
128int clock_gettime (clockid_t, struct timespec *);
e5f14be3 129#ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */
320054e8
DG
130int clock_settime (clockid_t, const struct timespec *);
131#endif
132int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *);
e5f14be3 133#ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */
320054e8
DG
134int clock_getcpuclockid (pid_t, clockid_t *);
135#endif
136
e5f14be3 137#ifdef __wasilibc_unmodified_upstream /* WASI has no timers */
320054e8
DG
138struct sigevent;
139int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict);
140int timer_delete (timer_t);
141int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict);
142int timer_gettime (timer_t, struct itimerspec *);
143int timer_getoverrun (timer_t);
144#endif
145
24f6fe1c 146#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */
320054e8 147extern char *tzname[2];
24f6fe1c 148#endif
320054e8
DG
149
150#endif
151
152
153#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
154char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
24f6fe1c 155#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */
320054e8
DG
156extern int daylight;
157extern long timezone;
24f6fe1c 158#endif
320054e8
DG
159extern int getdate_err;
160struct tm *getdate (const char *);
161#endif
162
163
164#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
e5f14be3 165#ifdef __wasilibc_unmodified_upstream /* WASI has no stime */
320054e8
DG
166int stime(const time_t *);
167#endif
168time_t timegm(struct tm *);
169#endif
170
575e1579
DG
171#if _REDIR_TIME64
172__REDIR(time, __time64);
173__REDIR(difftime, __difftime64);
174__REDIR(mktime, __mktime64);
175__REDIR(gmtime, __gmtime64);
176__REDIR(localtime, __localtime64);
177__REDIR(ctime, __ctime64);
178__REDIR(timespec_get, __timespec_get_time64);
179#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
180 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
181 || defined(_BSD_SOURCE)
182__REDIR(gmtime_r, __gmtime64_r);
183__REDIR(localtime_r, __localtime64_r);
184__REDIR(ctime_r, __ctime64_r);
185__REDIR(nanosleep, __nanosleep_time64);
186__REDIR(clock_getres, __clock_getres_time64);
187__REDIR(clock_gettime, __clock_gettime64);
188__REDIR(clock_settime, __clock_settime64);
189__REDIR(clock_nanosleep, __clock_nanosleep_time64);
190__REDIR(timer_settime, __timer_settime64);
191__REDIR(timer_gettime, __timer_gettime64);
192#endif
193#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
194__REDIR(stime, __stime64);
195__REDIR(timegm, __timegm_time64);
196#endif
197#endif
198
320054e8
DG
199#ifdef __cplusplus
200}
201#endif
202
203
204#endif