Skip to content

Commit

Permalink
don't use timespecsub() because it isn't on OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
guijan committed May 15, 2023
1 parent 759d3ee commit 7c43218
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 2 additions & 11 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ 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])
])
# 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 All @@ -78,9 +68,10 @@ AC_SUBST([CPPFLAGS], ["$X11_CFLAGS $XCOMPOSITE_CFLAGS $XEXT_CFLAGS \
# Checks for header files.
AC_CHECK_HEADERS([stdint.h sys/time.h unistd.h])

# Required: Checks for library functions.
# Checks for library functions.
AC_CHECK_FUNCS([getopt_long getsubopt gethostname strdup strerror strndup strtol],,
AC_MSG_ERROR([required functions are not present.]))
AC_CHECK_FUNCS([clock_nanosleep])

AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
13 changes: 11 additions & 2 deletions src/scrot.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>

#include <assert.h>
Expand Down Expand Up @@ -323,7 +322,17 @@ static void scrotWaitUntil(const struct timespec *time)
struct timespec tmp;
do {
clock_gettime(CLOCK_MONOTONIC, &tmp);
timespecsub(time, &tmp, &tmp);

/* XXX: Use timespecsub(). 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.
*/
tmp.tv_sec = time->tv_sec - tmp.tv_sec;
tmp.tv_nsec = time->tv_nsec - tmp.tv_nsec;
if (tmp.tv_nsec < 0) {
tmp.tv_sec--;
tmp.tv_nsec += 1000000000L;
}
} while (nanosleep(&tmp, &tmp) == -1 && errno == EINTR);
#endif
errno = savedErrno;
Expand Down

0 comments on commit 7c43218

Please sign in to comment.