1 #pragma once
2 
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #include <features.h>
8 #include <bits/null.h>
9 
10 #define __NEED_size_t
11 #define __NEED_time_t
12 #define __NEED_clock_t
13 #define __NEED_struct_timespec
14 
15 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
16     defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
17 #define __NEED_clockid_t
18 #define __NEED_timer_t
19 #define __NEED_pid_t
20 #endif
21 
22 #include <bits/alltypes.h>
23 
24 #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
25 #define __tm_gmtoff tm_gmtoff
26 #define __tm_zone tm_zone
27 #endif
28 
29 struct tm {
30     int tm_sec;
31     int tm_min;
32     int tm_hour;
33     int tm_mday;
34     int tm_mon;
35     int tm_year;
36     int tm_wday;
37     int tm_yday;
38     int tm_isdst;
39     long __tm_gmtoff;
40     const char* __tm_zone;
41 };
42 
43 clock_t clock(void);
44 time_t time(time_t*);
45 double difftime(time_t, time_t);
46 time_t mktime(struct tm*);
47 size_t strftime(char* __restrict, size_t, const char* __restrict, const struct tm* __restrict);
48 struct tm* gmtime(const time_t*);
49 struct tm* localtime(const time_t*);
50 char* asctime(const struct tm*);
51 char* ctime(const time_t*);
52 int timespec_get(struct timespec*, int);
53 
54 #define CLOCKS_PER_SEC 1000000L
55 
56 #define TIME_UTC 1
57 
58 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
59     defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
60 
61 struct tm* gmtime_r(const time_t* __restrict, struct tm* __restrict);
62 struct tm* localtime_r(const time_t* __restrict, struct tm* __restrict);
63 char* asctime_r(const struct tm* __restrict, char* __restrict);
64 char* ctime_r(const time_t*, char*);
65 
66 void tzset(void);
67 
68 struct itimerspec {
69     struct timespec it_interval;
70     struct timespec it_value;
71 };
72 
73 #define CLOCK_REALTIME 0
74 #define CLOCK_MONOTONIC 1
75 #define CLOCK_PROCESS_CPUTIME_ID 2
76 #define CLOCK_THREAD_CPUTIME_ID 3
77 #define CLOCK_MONOTONIC_RAW 4
78 #define CLOCK_REALTIME_COARSE 5
79 #define CLOCK_MONOTONIC_COARSE 6
80 #define CLOCK_BOOTTIME 7
81 #define CLOCK_REALTIME_ALARM 8
82 #define CLOCK_BOOTTIME_ALARM 9
83 #define CLOCK_SGI_CYCLE 10
84 #define CLOCK_TAI 11
85 
86 #define TIMER_ABSTIME 1
87 
88 int nanosleep(const struct timespec*, struct timespec*);
89 int clock_getres(clockid_t, struct timespec*);
90 int clock_gettime(clockid_t, struct timespec*);
91 int clock_settime(clockid_t, const struct timespec*);
92 int clock_nanosleep(clockid_t, int, const struct timespec*, struct timespec*);
93 int clock_getcpuclockid(pid_t, clockid_t*);
94 
95 struct sigevent;
96 int timer_create(clockid_t, struct sigevent* __restrict, timer_t* __restrict);
97 int timer_delete(timer_t);
98 int timer_settime(timer_t, int, const struct itimerspec* __restrict, struct itimerspec* __restrict);
99 int timer_gettime(timer_t, struct itimerspec*);
100 int timer_getoverrun(timer_t);
101 
102 #endif
103 
104 #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
105 char* strptime(const char* __restrict, const char* __restrict, struct tm* __restrict);
106 extern int daylight;
107 extern long timezone;
108 extern char* tzname[2];
109 extern int getdate_err;
110 struct tm* getdate(const char*);
111 #endif
112 
113 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
114 int stime(const time_t*);
115 time_t timegm(struct tm*);
116 #endif
117 
118 #ifdef __cplusplus
119 }
120 #endif
121