From: brarcher Date: Thu, 24 Oct 2013 02:14:55 +0000 (+0000) Subject: change check for valid clockid X-Git-Tag: 0.10.0~367 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a4bfda9109ad9885329e116e9405f8af61ffed8;p=check change check for valid clockid cygwin does not support CLOCK_MONOTONIC. However, a call to clock_gettime(CLOCK_MONOTONIC, ...) will pass, whereas a timer_create(CLOCK_MONOTONIC, ...) will fail. Use the timer_create() call for the check instead. However, be careful to only make the check if librt is available, otherwise it is a waste. Or worse, if librt and alarm() are unavailable, a timer_delete() will result in an assert(0). git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@847 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/src/check.c b/src/check.c index 76e6c5e..d7806d7 100644 --- a/src/check.c +++ b/src/check.c @@ -473,15 +473,27 @@ clockid_t check_get_clockid() if(clockid == -1) { - struct timespec ts; - if(clock_gettime(CLOCK_MONOTONIC, &ts) == 0) +/* + * Only check if we have librt available. Otherwise, the clockid + * will be ignored anyway, as the clock_gettime() and + * timer_create() functions will be re-implemented in libcompat. + * Worse, if librt and alarm() are unavailable, this check + * will result in an assert(0). + */ +#ifdef HAVE_LIBRT + timer_t timerid; + if(timer_create(CLOCK_MONOTONIC, NULL, &timerid) == 0) { + timer_delete(timerid); clockid = CLOCK_MONOTONIC; } else { clockid = CLOCK_REALTIME; } +#else + clockid = CLOCK_MONOTONIC; +#endif } return clockid;