time.h revision be149e8c
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
12struct 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
23struct timezone {
24	int tz_minuteswest;
25	int tz_dsttime;
26};
27
28struct 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
39extern "C" {
40#endif
41
42extern int	getitimer(int which, struct itimerval *value);
43extern int	setitimer(int which, const struct itimerval *value, struct itimerval *oldValue);
44extern int	gettimeofday(struct timeval *tv, void *tz);
45
46extern int	utimes(const char *path, const struct timeval times[2]);
47extern int	lutimes(const char *path, const struct timeval times[2]);
48	/* legacy */
49
50#ifdef __cplusplus
51}
52#endif
53
54/* BSDish macros operating on timeval structs */
55#define timeradd(a, b, res)								\
56	do {												\
57		(res)->tv_sec = (a)->tv_sec + (b)->tv_sec;		\
58		(res)->tv_usec = (a)->tv_usec + (b)->tv_usec;	\
59		if ((res)->tv_usec >= 1000000) {				\
60			(res)->tv_usec -= 1000000;					\
61			(res)->tv_sec++;							\
62		}												\
63	} while (0)
64#define timersub(a, b, res)								\
65	do {												\
66		(res)->tv_sec = (a)->tv_sec - (b)->tv_sec;		\
67		(res)->tv_usec = (a)->tv_usec - (b)->tv_usec;	\
68		if ((res)->tv_usec < 0) {						\
69			(res)->tv_usec += 1000000;					\
70			(res)->tv_sec--;							\
71		}												\
72	} while (0)
73#define timerclear(a)	((a)->tv_sec = (a)->tv_usec = 0)
74#define timerisset(a)	((a)->tv_sec != 0 || (a)->tv_usec != 0)
75#define timercmp(a, b, cmp)	((a)->tv_sec == (b)->tv_sec \
76		? (a)->tv_usec cmp (b)->tv_usec : (a)->tv_sec cmp (b)->tv_sec)
77
78#endif	/* _SYS_TIME_H */
79