10fae8733SScott McCreary /* 2173f54f1SMatt Madia * Copyright 2002-2012 Haiku, Inc. All Rights Reserved. 30fae8733SScott McCreary * Distributed under the terms of the MIT License. 40fae8733SScott McCreary */ 5d068515fSAxel Dörfler #ifndef _SYS_TIME_H 6d068515fSAxel Dörfler #define _SYS_TIME_H 7d068515fSAxel Dörfler 8d068515fSAxel Dörfler 9d068515fSAxel Dörfler #include <sys/types.h> 10d068515fSAxel Dörfler 11d068515fSAxel Dörfler 12d068515fSAxel Dörfler struct timeval { 132dc3fee5SAxel Dörfler time_t tv_sec; /* seconds */ 142dc3fee5SAxel Dörfler suseconds_t tv_usec; /* microseconds */ 15d068515fSAxel Dörfler }; 16d068515fSAxel Dörfler 17d068515fSAxel Dörfler #include <sys/select.h> 18d068515fSAxel Dörfler /* circular dependency: fd_set needs to be defined and the 19d068515fSAxel Dörfler * select prototype exported by this file, but <sys/select.h> 20d068515fSAxel Dörfler * needs struct timeval. 21d068515fSAxel Dörfler */ 22d068515fSAxel Dörfler 23d068515fSAxel Dörfler struct timezone { 24d068515fSAxel Dörfler int tz_minuteswest; 25d068515fSAxel Dörfler int tz_dsttime; 26d068515fSAxel Dörfler }; 27d068515fSAxel Dörfler 28d068515fSAxel Dörfler struct itimerval { 29d068515fSAxel Dörfler struct timeval it_interval; 30d068515fSAxel Dörfler struct timeval it_value; 31d068515fSAxel Dörfler }; 32d068515fSAxel Dörfler 33d068515fSAxel Dörfler #define ITIMER_REAL 1 /* real time */ 34d068515fSAxel Dörfler #define ITIMER_VIRTUAL 2 /* process virtual time */ 35d068515fSAxel Dörfler #define ITIMER_PROF 3 /* both */ 36d068515fSAxel Dörfler 37d068515fSAxel Dörfler 38d068515fSAxel Dörfler #ifdef __cplusplus 39d068515fSAxel Dörfler extern "C" { 40d068515fSAxel Dörfler #endif 41d068515fSAxel Dörfler 42d068515fSAxel Dörfler extern int getitimer(int which, struct itimerval *value); 43d068515fSAxel Dörfler extern int setitimer(int which, const struct itimerval *value, struct itimerval *oldValue); 447e965f50SOliver Tappe extern int gettimeofday(struct timeval *tv, void *tz); 45d068515fSAxel Dörfler 46*be149e8cSAlexander von Gluck IV extern int utimes(const char *path, const struct timeval times[2]); 47d068515fSAxel Dörfler /* legacy */ 48d068515fSAxel Dörfler 49d068515fSAxel Dörfler #ifdef __cplusplus 50d068515fSAxel Dörfler } 51d068515fSAxel Dörfler #endif 52d068515fSAxel Dörfler 531bc2fbc2SIngo Weinhold /* BSDish macros operating on timeval structs */ 541bc2fbc2SIngo Weinhold #define timeradd(a, b, res) \ 551bc2fbc2SIngo Weinhold do { \ 561bc2fbc2SIngo Weinhold (res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 571bc2fbc2SIngo Weinhold (res)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 581bc2fbc2SIngo Weinhold if ((res)->tv_usec >= 1000000) { \ 591bc2fbc2SIngo Weinhold (res)->tv_usec -= 1000000; \ 601bc2fbc2SIngo Weinhold (res)->tv_sec++; \ 611bc2fbc2SIngo Weinhold } \ 621bc2fbc2SIngo Weinhold } while (0) 631bc2fbc2SIngo Weinhold #define timersub(a, b, res) \ 641bc2fbc2SIngo Weinhold do { \ 651bc2fbc2SIngo Weinhold (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 661bc2fbc2SIngo Weinhold (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 671bc2fbc2SIngo Weinhold if ((res)->tv_usec < 0) { \ 681bc2fbc2SIngo Weinhold (res)->tv_usec += 1000000; \ 691bc2fbc2SIngo Weinhold (res)->tv_sec--; \ 701bc2fbc2SIngo Weinhold } \ 711bc2fbc2SIngo Weinhold } while (0) 721bc2fbc2SIngo Weinhold #define timerclear(a) ((a)->tv_sec = (a)->tv_usec = 0) 731bc2fbc2SIngo Weinhold #define timerisset(a) ((a)->tv_sec != 0 || (a)->tv_usec != 0) 741bc2fbc2SIngo Weinhold #define timercmp(a, b, cmp) ((a)->tv_sec == (b)->tv_sec \ 751bc2fbc2SIngo Weinhold ? (a)->tv_usec cmp (b)->tv_usec : (a)->tv_sec cmp (b)->tv_sec) 761bc2fbc2SIngo Weinhold 77d068515fSAxel Dörfler #endif /* _SYS_TIME_H */ 78