From 7af3ba340d608860d519210032d190c26c6f6eae Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sun, 6 Jan 2019 13:20:29 -0600 Subject: add configure-time check for timespecsub --- CMakeLists.txt | 5 +++++ include/compat/time.h | 7 ++++++- m4/check-libc.m4 | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1efe6bc..bcba254 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,6 +237,11 @@ if(HAVE_GETPAGESIZE) add_definitions(-DHAVE_GETPAGESIZE) endif() +check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB) +if(HAVE_TIMESPECSUB) + add_definitions(-DHAVE_TIMESPECSUB) +endif() + check_function_exists(timingsafe_bcmp HAVE_TIMINGSAFE_BCMP) if(HAVE_TIMINGSAFE_BCMP) add_definitions(-DHAVE_TIMINGSAFE_BCMP) diff --git a/include/compat/time.h b/include/compat/time.h index ccedba3..540807d 100644 --- a/include/compat/time.h +++ b/include/compat/time.h @@ -39,7 +39,11 @@ typedef int clockid_t; int clock_gettime(clockid_t clock_id, struct timespec *tp); #endif -#ifndef timespecsub +#ifdef timespecsub +#define HAVE_TIMESPECSUB +#endif + +#ifndef HAVE_TIMESPECSUB #define timespecsub(tsp, usp, vsp) \ do { \ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ @@ -50,6 +54,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp); } \ } while (0) #endif + #endif #endif diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 1fff77e..f726a43 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 @@ -5,7 +5,7 @@ AC_CHECK_HEADERS([err.h readpassphrase.h]) AC_CHECK_FUNCS([asprintf freezero memmem]) AC_CHECK_FUNCS([readpassphrase reallocarray recallocarray]) AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) -AC_CHECK_FUNCS([timegm _mkgmtime]) +AC_CHECK_FUNCS([timegm _mkgmtime timespecsub]) AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ AC_LINK_IFELSE([AC_LANG_PROGRAM([[ // Since Android NDK v16 getpagesize is defined as inline inside unistd.h @@ -22,6 +22,7 @@ AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) +AM_CONDITIONAL([HAVE_TIMESPECSUB], [test "x$ac_cv_func_timespecsub" = xyes]) AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) AM_CONDITIONAL([HAVE_READPASSPHRASE], [test "x$ac_cv_func_readpassphrase" = xyes]) AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) -- cgit v1.2.3-55-g6feb