1 #ifndef _SYS_TIME_H 2 #define _SYS_TIME_H 3 /* 4 ** Distributed under the terms of the OpenBeOS License. 5 */ 6 7 8 #include <sys/types.h> 9 10 11 struct timeval { 12 time_t tv_sec; /* seconds */ 13 suseconds_t tv_usec; /* microseconds */ 14 }; 15 16 #include <sys/select.h> 17 /* circular dependency: fd_set needs to be defined and the 18 * select prototype exported by this file, but <sys/select.h> 19 * needs struct timeval. 20 */ 21 22 struct timezone { 23 int tz_minuteswest; 24 int tz_dsttime; 25 }; 26 27 struct itimerval { 28 struct timeval it_interval; 29 struct timeval it_value; 30 }; 31 32 #define ITIMER_REAL 1 /* real time */ 33 #define ITIMER_VIRTUAL 2 /* process virtual time */ 34 #define ITIMER_PROF 3 /* both */ 35 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 extern int getitimer(int which, struct itimerval *value); 42 extern int setitimer(int which, const struct itimerval *value, struct itimerval *oldValue); 43 extern int gettimeofday(struct timeval *tv, struct timezone *tz); 44 45 extern int utimes(const char *name, const struct timeval times[2]); 46 /* legacy */ 47 48 #ifdef __cplusplus 49 } 50 #endif 51 52 /* BSDish macros operating on timeval structs */ 53 #define timeradd(a, b, res) \ 54 do { \ 55 (res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 56 (res)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 57 if ((res)->tv_usec >= 1000000) { \ 58 (res)->tv_usec -= 1000000; \ 59 (res)->tv_sec++; \ 60 } \ 61 } while (0) 62 #define timersub(a, b, res) \ 63 do { \ 64 (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 65 (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 66 if ((res)->tv_usec < 0) { \ 67 (res)->tv_usec += 1000000; \ 68 (res)->tv_sec--; \ 69 } \ 70 } while (0) 71 #define timerclear(a) ((a)->tv_sec = (a)->tv_usec = 0) 72 #define timerisset(a) ((a)->tv_sec != 0 || (a)->tv_usec != 0) 73 #define timercmp(a, b, cmp) ((a)->tv_sec == (b)->tv_sec \ 74 ? (a)->tv_usec cmp (b)->tv_usec : (a)->tv_sec cmp (b)->tv_sec) 75 76 #endif /* _SYS_TIME_H */ 77