]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/include/time.h
bump version to 0.0~git20240411.9e8c542-3~bpo12+pve1
[wasi-libc.git] / libc-top-half / musl / include / time.h
1 #ifndef _TIME_H
2 #define _TIME_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <features.h>
9
10 #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
11 #if __cplusplus >= 201103L
12 #define NULL nullptr
13 #elif defined(__cplusplus)
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
45 #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
46 struct 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
63 #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS)
64 clock_t clock (void);
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 )))
71 clock_t clock (void);
72 #endif
73 time_t time (time_t *);
74 double difftime (time_t, time_t);
75 time_t mktime (struct tm *);
76 size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict);
77 struct tm *gmtime (const time_t *);
78 struct tm *localtime (const time_t *);
79 char *asctime (const struct tm *);
80 char *ctime (const time_t *);
81 int timespec_get(struct timespec *, int);
82
83 #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
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
93 size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t);
94
95 struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
96 struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
97 char *asctime_r (const struct tm *__restrict, char *__restrict);
98 char *ctime_r (const time_t *, char *);
99
100 #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */
101 void tzset (void);
102 #endif
103
104 struct itimerspec {
105 struct timespec it_interval;
106 struct timespec it_value;
107 };
108
109 #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
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
126 int nanosleep (const struct timespec *, struct timespec *);
127 int clock_getres (clockid_t, struct timespec *);
128 int clock_gettime (clockid_t, struct timespec *);
129 #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */
130 int clock_settime (clockid_t, const struct timespec *);
131 #endif
132 int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *);
133 #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */
134 int clock_getcpuclockid (pid_t, clockid_t *);
135 #endif
136
137 #ifdef __wasilibc_unmodified_upstream /* WASI has no timers */
138 struct sigevent;
139 int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict);
140 int timer_delete (timer_t);
141 int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict);
142 int timer_gettime (timer_t, struct itimerspec *);
143 int timer_getoverrun (timer_t);
144 #endif
145
146 #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */
147 extern char *tzname[2];
148 #endif
149
150 #endif
151
152
153 #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
154 char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
155 #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */
156 extern int daylight;
157 extern long timezone;
158 #endif
159 extern int getdate_err;
160 struct tm *getdate (const char *);
161 #endif
162
163
164 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
165 #ifdef __wasilibc_unmodified_upstream /* WASI has no stime */
166 int stime(const time_t *);
167 #endif
168 time_t timegm(struct tm *);
169 #endif
170
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
199 #ifdef __cplusplus
200 }
201 #endif
202
203
204 #endif