Skip to content

Commit

Permalink
don't use timespeccmp()/timespecsub()
Browse files Browse the repository at this point in the history
There's no compat library for OS X that provides them yet.
  • Loading branch information
guijan committed Apr 11, 2023
1 parent 7f6a570 commit 1647a6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
11 changes: 1 addition & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,7 @@ AC_ARG_ENABLE([libbsd-feature-test],
AC_CHECK_FUNCS([err errx warn warnx],,
[LIBBSD_NEEDED=yes])
AC_CHECK_HEADERS([sys/queue.h],, [LIBBSD_NEEDED=yes])
AC_CHECK_FUNCS([clock_nanosleep],, [
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([
#include <sys/time.h>
#if !defined(timespecsub) || !defined(timespeccmp)
#error "timespecsub or timespeccmp not found"
#endif
])
],, [LIBBSD_NEEDED=yes])
])
AC_CHECK_FUNCS([clock_nanosleep])
# libbsd is obligatory on systems that don't have the BSD functions we use.
# Pass "--enable-libbsd-feature-test" to ./configure, and the configure script
# will tell you whether the library is a dependency. This option is intended to
Expand Down
17 changes: 15 additions & 2 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,22 @@ clock_nanosleep(clockid_t clock, int flags, const struct timespec *timeout,
if (flags == TIMER_ABSTIME) {
if (clock_gettime(clock, &tmp) == -1)
return -1;
if (timespeccmp(&tmp, timeout, >=))

/* XXX: Use timespeccmp(). OS X doesn't have that BSD macro, and libbsd
* doesn't support OS X save for an unmaintained fork. libobsd supports
* OS X but doesn't have the macro yet.
*/
if (tmp.tv_sec == timeout->tv_sec ?
tmp.tv_nsec >= timeout->tv_nsec : tmp.tv_sec >= timeout->tv_sec)
return 0;
timespecsub(timeout, &tmp, &tmp);
/* XXX: Use timespecsub(). Same issues as timespeccmp(). */
tmp.tv_sec -= timeout->tv_sec;
tmp.tv_nsec -= timeout->tv_nsec;
if (tmp.tv_nsec < 0) {
tmp.tv_sec--;
tmp.tv_nsec += 1000000000;
}

remainder = NULL;
}
return nanosleep(&tmp, remainder);
Expand Down

0 comments on commit 1647a6d

Please sign in to comment.