1 #ifndef _SYS_TIME_H
2 #define _SYS_TIME_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #include <features.h>
8 
9 #include <sys/select.h>
10 
11 int gettimeofday (struct timeval *__restrict, void *__restrict);
12 
13 #ifdef __wasilibc_unmodified_upstream /* WASI has no getitimer */
14 #define ITIMER_REAL    0
15 #define ITIMER_VIRTUAL 1
16 #define ITIMER_PROF    2
17 
18 struct itimerval {
19 	struct timeval it_interval;
20 	struct timeval it_value;
21 };
22 
23 int getitimer (int, struct itimerval *);
24 int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict);
25 #endif
26 #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
27 int utimes (const char *, const struct timeval [2]);
28 #endif
29 
30 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
31 struct timezone {
32 	int tz_minuteswest;
33 	int tz_dsttime;
34 };
35 #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
36 int futimes(int, const struct timeval [2]);
37 int futimesat(int, const char *, const struct timeval [2]);
38 int lutimes(const char *, const struct timeval [2]);
39 #endif
40 #ifdef __wasilibc_unmodified_upstream /* WASI has no way to set the time */
41 int settimeofday(const struct timeval *, const struct timezone *);
42 int adjtime (const struct timeval *, struct timeval *);
43 #endif
44 #define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
45 #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
46 #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
47 	(s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
48 #define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
49 	((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
50 	((a)->tv_usec -= 1000000, (a)->tv_sec++) )
51 #define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
52 	((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
53 	((a)->tv_usec += 1000000, (a)->tv_sec--) )
54 #endif
55 
56 #if defined(_GNU_SOURCE)
57 #define TIMEVAL_TO_TIMESPEC(tv, ts) ( \
58 	(ts)->tv_sec = (tv)->tv_sec, \
59 	(ts)->tv_nsec = (tv)->tv_usec * 1000, \
60 	(void)0 )
61 #define TIMESPEC_TO_TIMEVAL(tv, ts) ( \
62 	(tv)->tv_sec = (ts)->tv_sec, \
63 	(tv)->tv_usec = (ts)->tv_nsec / 1000, \
64 	(void)0 )
65 #endif
66 
67 #if _REDIR_TIME64
68 __REDIR(gettimeofday, __gettimeofday_time64);
69 __REDIR(getitimer, __getitimer_time64);
70 __REDIR(setitimer, __setitimer_time64);
71 __REDIR(utimes, __utimes_time64);
72 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
73 __REDIR(futimes, __futimes_time64);
74 __REDIR(futimesat, __futimesat_time64);
75 __REDIR(lutimes, __lutimes_time64);
76 __REDIR(settimeofday, __settimeofday_time64);
77 __REDIR(adjtime, __adjtime64);
78 #endif
79 #endif
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 #endif
85