OLD | NEW |
1 #ifndef _SYS_TIME_H | 1 #ifndef _SYS_TIME_H |
2 #define _SYS_TIME_H | 2 #define _SYS_TIME_H |
3 #ifdef __cplusplus | 3 #ifdef __cplusplus |
4 extern "C" { | 4 extern "C" { |
5 #endif | 5 #endif |
6 | 6 |
7 #include <features.h> | 7 #include <features.h> |
8 | 8 |
9 #include <sys/select.h> | 9 #include <sys/select.h> |
10 | 10 |
11 int gettimeofday (struct timeval *__restrict, void *__restrict); | 11 int gettimeofday(struct timeval* __restrict, void* __restrict); |
12 | 12 |
13 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | 13 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
14 || defined(_BSD_SOURCE) | |
15 | 14 |
16 #define ITIMER_REAL 0 | 15 #define ITIMER_REAL 0 |
17 #define ITIMER_VIRTUAL 1 | 16 #define ITIMER_VIRTUAL 1 |
18 #define ITIMER_PROF 2 | 17 #define ITIMER_PROF 2 |
19 | 18 |
20 struct itimerval | 19 struct itimerval { |
21 { | 20 struct timeval it_interval; |
22 » struct timeval it_interval; | 21 struct timeval it_value; |
23 » struct timeval it_value; | |
24 }; | 22 }; |
25 | 23 |
26 int getitimer (int, struct itimerval *); | 24 int getitimer(int, struct itimerval*); |
27 int setitimer (int, const struct itimerval *__restrict, struct itimerval *__rest
rict); | 25 int setitimer(int, |
28 int utimes (const char *, const struct timeval [2]); | 26 const struct itimerval* __restrict, |
| 27 struct itimerval* __restrict); |
| 28 int utimes(const char*, const struct timeval[2]); |
29 | 29 |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | 32 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
33 struct timezone { | 33 struct timezone { |
34 » int tz_minuteswest; | 34 int tz_minuteswest; |
35 » int tz_dsttime; | 35 int tz_dsttime; |
36 }; | 36 }; |
37 int futimes(int, const struct timeval [2]); | 37 int futimes(int, const struct timeval[2]); |
38 int futimesat(int, const char *, const struct timeval [2]); | 38 int futimesat(int, const char*, const struct timeval[2]); |
39 int lutimes(const char *, const struct timeval [2]); | 39 int lutimes(const char*, const struct timeval[2]); |
40 int settimeofday(const struct timeval *, const struct timezone *); | 40 int settimeofday(const struct timeval*, const struct timezone*); |
41 int adjtime (const struct timeval *, struct timeval *); | 41 int adjtime(const struct timeval*, struct timeval*); |
42 #define timerisset(t) ((t)->tv_sec || (t)->tv_usec) | 42 #define timerisset(t) ((t)->tv_sec || (t)->tv_usec) |
43 #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) | 43 #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) |
44 #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ | 44 #define timercmp(s, t, op) \ |
45 » (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) | 45 ((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op(t)->tv_usec \ |
46 #define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ | 46 : (s)->tv_sec op(t)->tv_sec) |
47 » ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \ | 47 #define timeradd(s, t, a) \ |
48 » ((a)->tv_usec -= 1000000, (a)->tv_sec++) ) | 48 (void)((a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ |
49 #define timersub(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 = (s)->tv_usec - (t)->tv_usec) < 0 && \ | 50 ((a)->tv_usec -= 1000000, (a)->tv_sec++)) |
51 » ((a)->tv_usec += 1000000, (a)->tv_sec--) ) | 51 #define timersub(s, t, a) \ |
| 52 (void)((a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \ |
| 53 ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \ |
| 54 ((a)->tv_usec += 1000000, (a)->tv_sec--)) |
52 #endif | 55 #endif |
53 | 56 |
54 #if defined(_GNU_SOURCE) | 57 #if defined(_GNU_SOURCE) |
55 #define TIMEVAL_TO_TIMESPEC(tv, ts) ( \ | 58 #define TIMEVAL_TO_TIMESPEC(tv, ts) \ |
56 » (ts)->tv_sec = (tv)->tv_sec, \ | 59 ((ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0) |
57 » (ts)->tv_nsec = (tv)->tv_usec * 1000, \ | 60 #define TIMESPEC_TO_TIMEVAL(tv, ts) \ |
58 » (void)0 ) | 61 ((tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0) |
59 #define TIMESPEC_TO_TIMEVAL(tv, ts) ( \ | |
60 » (tv)->tv_sec = (ts)->tv_sec, \ | |
61 » (tv)->tv_usec = (ts)->tv_nsec / 1000, \ | |
62 » (void)0 ) | |
63 #endif | 62 #endif |
64 | 63 |
65 #ifdef __cplusplus | 64 #ifdef __cplusplus |
66 } | 65 } |
67 #endif | 66 #endif |
68 #endif | 67 #endif |
OLD | NEW |