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