vfs: check userland buffers before reading them.
[haiku.git] / headers / posix / sys / time.h
blobdfa8d8cf233df36a84e7b5120bd4942bb244aa3f
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
9 #include <sys/types.h>
12 struct timeval {
13 time_t tv_sec; /* seconds */
14 suseconds_t tv_usec; /* microseconds */
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.
23 struct timezone {
24 int tz_minuteswest;
25 int tz_dsttime;
28 struct itimerval {
29 struct timeval it_interval;
30 struct timeval it_value;
33 #define ITIMER_REAL 1 /* real time */
34 #define ITIMER_VIRTUAL 2 /* process virtual time */
35 #define ITIMER_PROF 3 /* both */
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
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);
46 extern int utimes(const char *path, const struct timeval times[2]);
47 /* legacy */
49 #ifdef __cplusplus
51 #endif
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)
77 #endif /* _SYS_TIME_H */