refactor headers, especially alltypes.h, and improve C++ ABI compat
[musl] / include / sys / time.h
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 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
14  || defined(_BSD_SOURCE)
15
16 #define ITIMER_REAL    0
17 #define ITIMER_VIRTUAL 1
18 #define ITIMER_PROF    2
19
20 struct itimerval
21 {
22         struct timeval it_interval;
23         struct timeval it_value;
24 };
25
26 int getitimer (int, struct itimerval *);
27 int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict);
28 int utimes (const char *, const struct timeval [2]);
29
30 #endif
31
32 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
33 struct timezone {
34         int tz_minuteswest;
35         int tz_dsttime;
36 };
37 int futimes(int, const struct timeval [2]);
38 int futimesat(int, const char *, const struct timeval [2]);
39 int lutimes(const char *, const struct timeval [2]);
40 int settimeofday(const struct timeval *, const struct timezone *);
41 int adjtime (const struct timeval *, struct timeval *);
42 #define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
43 #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
44 #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
45         (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
46 #define timeradd(s,t,a) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
47         ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
48         ((a)->tv_usec -= 1000000, (a)->tv_sec++) )
49 #define timersub(s,t,a) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
50         ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
51         ((a)->tv_usec += 1000000, (a)->tv_sec--) )
52 #endif
53
54 #ifdef __cplusplus
55 }
56 #endif
57 #endif