commit: d595cab75b9ec1e3a98536f5591a02d1f2d6102a
parent: abb8d4dd35eeeddb691ebd7d97ced8b76679026e
author: Tim Sedlmeyer <tim@sedlmeyer.org>
date: Mon, 4 Jun 2018 03:22:01 -0400
Add check for timeradd/timersub and implementations
2 files changed, 72 insertions(+)
diff --git a/configure b/configure
@@ -298,6 +298,36 @@ EOF
fi
}
+timeraddcheck() {
+ cat << EOF > conftest.c
+#include <sys/time.h>
+int main(void){struct timeval a, b, res;timeradd(&a, &b, &res);return 0;}
+EOF
+ $cc $tflags -o conftest conftest.c > /dev/null 2>&1
+ if [ $? -eq 0 ] ; then
+ rm -f conftest conftest.c
+ return 0
+ else
+ rm -f conftest conftest.c
+ return 1
+ fi
+}
+
+timersubcheck() {
+ cat << EOF > conftest.c
+#include <sys/time.h>
+int main(void){struct timeval a, b, res;timersub(&a, &b, &res);return 0;}
+EOF
+ $cc $tflags -o conftest conftest.c > /dev/null 2>&1
+ if [ $? -eq 0 ] ; then
+ rm -f conftest conftest.c
+ return 0
+ else
+ rm -f conftest conftest.c
+ return 1
+ fi
+}
+
wflagcheck() {
cat << EOF > conftest.c
int main(void){return 0;}
@@ -577,6 +607,24 @@ else
echo "no"
fi
+printf "checking for timeradd... "
+timeraddcheck
+if [ $? -eq 0 ] ; then
+ echo "#define HAVE_TIMERADD" >> pconfig.h
+ echo "yes"
+else
+ echo "no"
+fi
+
+printf "checking for timersub... "
+timersubcheck
+if [ $? -eq 0 ] ; then
+ echo "#define HAVE_TIMERSUB" >> pconfig.h
+ echo "yes"
+else
+ echo "no"
+fi
+
printf "creating Makefile... "
cat << EOF > Makefile
# This Makefile automatically generated by configure.
diff --git a/portable.h b/portable.h
@@ -88,6 +88,30 @@
#define srand_deterministic(x) srand(x)
#endif /* !HAVE_SRAND_DETERMINISTIC */
+#ifndef HAVE_TIMERADD
+#define timeradd(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
+ if ((vvp)->tv_usec >= 1000000) { \
+ (vvp)->tv_sec++; \
+ (vvp)->tv_usec -= 1000000; \
+ } \
+ } while (0)
+#endif /* !HAVE_TIMERADD */
+
+#ifndef HAVE_TIMERSUB
+#define timersub(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
+ if ((vvp)->tv_usec < 0) { \
+ (vvp)->tv_sec--; \
+ (vvp)->tv_usec += 1000000; \
+ } \
+ } while (0)
+#endif /* !HAVE_TIMERSUB */
+
/* struct stat compatibility */
#ifdef __APPLE__
#define st_mtim st_mtimespec