| 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 | #define ITIMER_REAL 0 |
| 14 | #define ITIMER_VIRTUAL 1 |
| 15 | #define ITIMER_PROF 2 |
| 16 | |
| 17 | struct itimerval { |
| 18 | 	struct timeval it_interval; |
| 19 | 	struct timeval it_value; |
| 20 | }; |
| 21 | |
| 22 | int getitimer (int, struct itimerval *); |
| 23 | int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict); |
| 24 | int utimes (const char *, const struct timeval [2]); |
| 25 | |
| 26 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 27 | struct timezone { |
| 28 | 	int tz_minuteswest; |
| 29 | 	int tz_dsttime; |
| 30 | }; |
| 31 | int futimes(int, const struct timeval [2]); |
| 32 | int futimesat(int, const char *, const struct timeval [2]); |
| 33 | int lutimes(const char *, const struct timeval [2]); |
| 34 | int settimeofday(const struct timeval *, const struct timezone *); |
| 35 | int adjtime (const struct timeval *, struct timeval *); |
| 36 | #define timerisset(t) ((t)->tv_sec || (t)->tv_usec) |
| 37 | #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) |
| 38 | #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ |
| 39 | 	(s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) |
| 40 | #define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ |
| 41 | 	((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \ |
| 42 | 	((a)->tv_usec -= 1000000, (a)->tv_sec++) ) |
| 43 | #define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \ |
| 44 | 	((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \ |
| 45 | 	((a)->tv_usec += 1000000, (a)->tv_sec--) ) |
| 46 | #endif |
| 47 | |
| 48 | #if defined(_GNU_SOURCE) |
| 49 | #define TIMEVAL_TO_TIMESPEC(tv, ts) ( \ |
| 50 | 	(ts)->tv_sec = (tv)->tv_sec, \ |
| 51 | 	(ts)->tv_nsec = (tv)->tv_usec * 1000, \ |
| 52 | 	(void)0 ) |
| 53 | #define TIMESPEC_TO_TIMEVAL(tv, ts) ( \ |
| 54 | 	(tv)->tv_sec = (ts)->tv_sec, \ |
| 55 | 	(tv)->tv_usec = (ts)->tv_nsec / 1000, \ |
| 56 | 	(void)0 ) |
| 57 | #endif |
| 58 | |
| 59 | #if _REDIR_TIME64 |
| 60 | __REDIR(gettimeofday, __gettimeofday_time64); |
| 61 | __REDIR(getitimer, __getitimer_time64); |
| 62 | __REDIR(setitimer, __setitimer_time64); |
| 63 | __REDIR(utimes, __utimes_time64); |
| 64 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 65 | __REDIR(futimes, __futimes_time64); |
| 66 | __REDIR(futimesat, __futimesat_time64); |
| 67 | __REDIR(lutimes, __lutimes_time64); |
| 68 | __REDIR(settimeofday, __settimeofday_time64); |
| 69 | __REDIR(adjtime, __adjtime64); |
| 70 | #endif |
| 71 | #endif |
| 72 | |
| 73 | #ifdef __cplusplus |
| 74 | } |
| 75 | #endif |
| 76 | #endif |