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