oksh-noxz

[fork] Portable OpenBSD ksh, based on the Public Domain Korn Shell (pdksh).
git clone https://noxz.tech/git/oksh-noxz.git
oksh-noxz

commit: b9b207c795539b54a7f9bc219d6be01a2b004b7d
parent: f0bab08b710bc1ee52e39ccacb76c5525c7337ce
author: Brian Callahan <bcallah@openbsd.org>
date:   Thu, 3 Jun 2021 13:52:11 -0400
Use old conversion of clock_gettime if on Mac OS X prior to 10.12
Fix #61
Mconfigure31++++++++++++++++++--
Mportable.h6++--
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/configure b/configure
@@ -200,6 +200,27 @@ EOF
   fi
 }
 
+clockgettimemacoscheck() {
+  cat << EOF > conftest.c
+int main(void) {
+#if defined(__APPLE__) && defined(__MACH__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
+return 0;
+#else
+return 1;
+#endif
+}
+EOF
+  $cc $cflags -o conftest.o -c conftest.c > /dev/null 2>&1
+  $cc $ldflags -o conftest conftest.o > /dev/null 2>&1
+  if [ $? -eq 0 ] ; then
+    rm -f conftest conftest.o conftest.c
+    return 0
+  else
+    rm -f conftest conftest.o conftest.c
+    return 1
+  fi
+}
+
 clockgettimertcheck() {
   cat << EOF > conftest.c
 #include <stdio.h>
@@ -1084,8 +1105,14 @@ else
     echo "yes"
   else
     echo "no"
-    echo "Error: oksh requires clock_gettime()"
-    exit 1
+    printf "checking if we are Mac OS X 10.11 or older... "
+    clockgettimemacoscheck
+    if [ $? -eq 0 ] ; then
+      echo "yes"
+    else
+      echo "Error: oksh requires clock_gettime()"
+      exit 1
+    fi
   fi
 fi
 
diff --git a/portable.h b/portable.h
@@ -88,8 +88,8 @@
 #define	RLIMIT_NPROC	7		/* number of processes */
 #endif /* !RLIMIT_NPROC */
 
-/* Convert clock_gettime() to clock_get_time() on Max OS X */
-#ifdef __APPLE__
+/* Convert clock_gettime() to clock_get_time() on Max OS X < 10.12 */
+#if defined(__APPLE__) && defined(__MACH__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
 #define clock_gettime(x, y)						\
 	clock_serv_t cclock;						\
 	mach_timespec_t mts;						\
@@ -98,7 +98,7 @@
 	mach_port_deallocate(mach_task_self(), cclock);			\
 	(y)->tv_sec = mts.tv_sec;					\
 	(y)->tv_nsec = mts.tv_nsec;
-#endif /* __APPLE__ */
+#endif /* __APPLE__ && __MACH__ && < 10.12 */
 
 #ifdef _AIX
 #define VWERASE VWERSE