haiku/headers/compatibility/bsd/sys/time.h
Jérôme Duval 01dc1ea4cf libbsd: add strtonum(), nitems(), timespec operation functions from FreeBSD
Change-Id: I56b677b382d17a27d243b615de19bec10f3a2810
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7426
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-02-26 14:06:29 +00:00

58 lines
1.4 KiB
C

/*
* Copyright 2016-2017 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _BSD_SYS_TIME_H_
#define _BSD_SYS_TIME_H_
#include_next <sys/time.h>
#include <features.h>
#ifdef _DEFAULT_SOURCE
/* BSDish macros operating on timespec structs */
#define timespecadd(a, b, res) \
do { \
(res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(res)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \
if ((res)->tv_nsec >= 1000000000L) { \
(res)->tv_nsec -= 1000000000L; \
(res)->tv_sec++; \
} \
} while (0)
#define timespecsub(a, b, res) \
do { \
(res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(res)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
if ((res)->tv_nsec < 0) { \
(res)->tv_nsec += 1000000000L; \
(res)->tv_sec--; \
} \
} while (0)
#define timespecclear(a) ((a)->tv_sec = (a)->tv_nsec = 0)
#define timespecisset(a) ((a)->tv_sec != 0 || (a)->tv_nsec != 0)
#define timespeccmp(a, b, cmp) (((a)->tv_sec == (b)->tv_sec) \
? (a)->tv_nsec cmp (b)->tv_nsec : (a)->tv_sec cmp (b)->tv_sec))
#define timespecvalid_interval(a) ((a)->tv_sec >= 0 \
&& (a)->tv_nsec >= 0 && (&)->tv_nsec < 1000000000L)
#ifdef __cplusplus
extern "C" {
#endif
int lutimes(const char *path, const struct timeval times[2]);
#ifdef __cplusplus
}
#endif
#endif
#endif /* _BSD_SYS_TIME_H_ */