summaryrefslogtreecommitdiffstats
path: root/src/H5time_private.h
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2019-10-07 17:15:40 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2019-10-07 17:15:40 (GMT)
commit730b2fbcb2605ed7958dc6009105cef4548e76c9 (patch)
tree90536b8fb83704c5459867d3eb86be9e62a62601 /src/H5time_private.h
parent19304abb517a5258275b8d15872931677151896f (diff)
downloadhdf5-730b2fbcb2605ed7958dc6009105cef4548e76c9.zip
hdf5-730b2fbcb2605ed7958dc6009105cef4548e76c9.tar.gz
hdf5-730b2fbcb2605ed7958dc6009105cef4548e76c9.tar.bz2
Provide the BSD `struct timespec` arithmetic macro, timespecsub().
Diffstat (limited to 'src/H5time_private.h')
-rw-r--r--src/H5time_private.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/H5time_private.h b/src/H5time_private.h
new file mode 100644
index 0000000..bc9f274
--- /dev/null
+++ b/src/H5time_private.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019 The HDF Group. All rights reserved.
+ *
+ * This file is part of HDF5. The full HDF5 copyright notice, including
+ * terms governing use, modification, and redistribution, is contained in
+ * the COPYING file, which can be found at the root of the source code
+ * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
+ * If you do not have access to either file, you may request a copy from
+ * help@hdfgroup.org.
+ */
+
+#ifndef _H5time_private_H
+#define _H5time_private_H
+
+#ifdef __NetBSD__
+#include <sys/time.h>
+#else
+#define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L)
+#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
+#define timespeccmp(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define timespecadd(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec >= 1000000000L) { \
+ (vsp)->tv_sec++; \
+ (vsp)->tv_nsec -= 1000000000L; \
+ } \
+ } while (/* CONSTCOND */ 0)
+#define timespecsub(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec < 0) { \
+ (vsp)->tv_sec--; \
+ (vsp)->tv_nsec += 1000000000L; \
+ } \
+ } while (/* CONSTCOND */ 0)
+#define timespec2ns(x) (((uint64_t)(x)->tv_sec) * 1000000000L + (x)->tv_nsec)
+#endif
+
+#endif /* _H5time_private_H */