1/*
2 * Copyright 2016-2017 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _BSD_SYS_TIME_H_
6#define _BSD_SYS_TIME_H_
7
8
9#include_next <sys/time.h>
10#include <features.h>
11
12
13#ifdef _DEFAULT_SOURCE
14
15
16/* BSDish macros operating on timespec structs */
17#define	timespecadd(a, b, res)							\
18	do {												\
19		(res)->tv_sec = (a)->tv_sec + (b)->tv_sec;		\
20		(res)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec;	\
21		if ((res)->tv_nsec >= 1000000000L) {			\
22			(res)->tv_nsec -= 1000000000L;				\
23			(res)->tv_sec++;							\
24		}												\
25	} while (0)
26#define	timespecsub(a, b, res)							\
27	do {												\
28		(res)->tv_sec = (a)->tv_sec - (b)->tv_sec;		\
29		(res)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec;	\
30		if ((res)->tv_nsec < 0) {						\
31			(res)->tv_nsec += 1000000000L;				\
32			(res)->tv_sec--;							\
33		}												\
34	} while (0)
35#define	timespecclear(a)	((a)->tv_sec = (a)->tv_nsec = 0)
36#define	timespecisset(a)	((a)->tv_sec != 0 || (a)->tv_nsec != 0)
37#define	timespeccmp(a, b, cmp)	(((a)->tv_sec == (b)->tv_sec) \
38	? ((a)->tv_nsec cmp (b)->tv_nsec) : ((a)->tv_sec cmp (b)->tv_sec))
39#define	timespecvalid_interval(a)	((a)->tv_sec >= 0	\
40	&& (a)->tv_nsec >= 0 && (&)->tv_nsec < 1000000000L)
41
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47int  lutimes(const char *path, const struct timeval times[2]);
48
49#ifdef __cplusplus
50}
51#endif
52
53
54#endif
55
56
57#endif  /* _BSD_SYS_TIME_H_ */
58