# MacOS has no clocktime_nanosleep

--- /dev/null	2022-10-30 11:00:38.000000000 +0800
+++ include/gavl/clock_nanosleep.h	2022-10-30 11:04:56.000000000 +0800
@@ -0,0 +1,27 @@
+#ifndef GAVL_CLOCK_NANOSLEEP_H_INCLUDED
+#define GAVL_CLOCK_NANOSLEEP_H_INCLUDED
+
+#include <time.h>
+#include <unistd.h>
+
+#ifdef __APPLE__
+// macOS <10.12 doesn't have clockid_t / CLOCK_MONOTONIC
+#ifndef CLOCK_MONOTONIC
+typedef int clockid_t;
+#define CLOCK_MONOTONIC 0
+#endif
+// macOS doesn't have clock_nanosleep
+static inline
+int clock_nanosleep(clockid_t clock_id, int flags,
+    const struct timespec *tm, struct timespec *rem)
+{
+    (void) clock_id;
+    (void) flags;
+    (void) tm;
+    (void) rem;
+    errno = ENOSYS;
+    return -1;
+}
+#endif // __APPLE__
+
+#endif // GAVL_CLOCK_NANOSLEEP_H_INCLUDED

--- include/gavl/Makefile.in.orig	2012-06-08 19:49:53.000000000 +0800
+++ include/gavl/Makefile.in	2022-10-30 10:22:15.000000000 +0800
@@ -215,7 +215,8 @@
 timecode.h \
 gavldefs.h \
 metadata.h \
-metatags.h
+metatags.h \
+clock_nanosleep.h
 
 EXTRA_DIST = gavl_version.h.in
 all: config.h

--- include/gavl/Makefile.am.orig	2012-06-08 19:49:30.000000000 +0800
+++ include/gavl/Makefile.am	2022-10-30 10:22:27.000000000 +0800
@@ -7,7 +7,7 @@
 timecode.h \
 gavldefs.h \
 metadata.h \
-metatags.h
-
+metatags.h \
+clock_nanosleep.h
 
 EXTRA_DIST = gavl_version.h.in

--- gavl/time.c.orig	2012-06-08 19:49:47.000000000 +0800
+++ gavl/time.c	2022-10-30 10:28:56.000000000 +0800
@@ -42,6 +42,9 @@
 #include <gavltime.h>
 #include <arith128.h>
 
+#ifdef __APPLE__
+#include <clock_nanosleep.h>
+#endif
 
 /* Sleep for a specified time */
 #ifdef HAVE_CLOCK_MONOTONIC
@@ -53,8 +56,7 @@
   tm.tv_sec = *t / 1000000;
   tm.tv_nsec = (*t % 1000000)*1000;
   
-  while(clock_nanosleep(CLOCK_MONOTONIC, 0,
-                        &tm, &rem))
+  while(clock_nanosleep(CLOCK_MONOTONIC, 0, &tm, &rem))
     {
     if(errno == EINTR)
       {

--- doc/Doxyfile.in.orig	2012-06-08 19:49:47.000000000 +0800
+++ doc/Doxyfile.in	2022-10-30 10:29:37.000000000 +0800
@@ -424,7 +424,7 @@
 # directories like "/usr/src/myproject". Separate the files or directories 
 # with spaces.
 
-INPUT = @TOP_SRCDIR@/doc/mainpage.incl @TOP_SRCDIR@/include/gavl/timecode.h @TOP_SRCDIR@/include/gavl/gavl.h @TOP_SRCDIR@/include/gavl/gavltime.h @TOP_SRCDIR@/include/gavl/gavldsp.h @TOP_SRCDIR@/include/gavl/compression.h @TOP_SRCDIR@/include/gavl/metadata.h @TOP_SRCDIR@/include/gavl/metatags.h
+INPUT = @TOP_SRCDIR@/doc/mainpage.incl @TOP_SRCDIR@/include/gavl/timecode.h @TOP_SRCDIR@/include/gavl/gavl.h @TOP_SRCDIR@/include/gavl/gavltime.h @TOP_SRCDIR@/include/gavl/gavldsp.h @TOP_SRCDIR@/include/gavl/compression.h @TOP_SRCDIR@/include/gavl/metadata.h @TOP_SRCDIR@/include/gavl/metatags.h @TOP_SRCDIR@/include/gavl/clock_nanosleep.h
 
 # If the value of the INPUT tag contains directories, you can use the 
 # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
