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: 832467341161469d6969477e5586ab1553194af1
parent: 5dd5c001f007c562816e0562a3cabfad24beee77
author: Tim Sedlmeyer <tim@sedlmeyer.org>
date:   Mon, 4 Jun 2018 14:25:37 -0400
Check for st_mtim and st_mtimespec. Fallback to st_mtime.
Mconfigure48++++++++++++++++++++
Mportable.h9+++-
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
@@ -236,6 +236,36 @@ EOF
   fi
 }
 
+st_mtimcheck() {
+  cat << EOF > conftest.c
+#include <sys/stat.h>
+int main(void){struct stat s;sizeof(s.st_mtim);return 0;}
+EOF
+  $cc $tflags -o conftest conftest.c > /dev/null 2>&1
+  if [ $? -eq 0 ] ; then
+    rm -f conftest conftest.c
+    return 0
+  else
+    rm -f conftest conftest.c
+    return 1
+  fi
+}
+
+st_mtimespeccheck() {
+  cat << EOF > conftest.c
+#include <sys/stat.h>
+int main(void){struct stat s;sizeof(s.st_mtimespec);return 0;}
+EOF
+  $cc $tflags -o conftest conftest.c > /dev/null 2>&1
+  if [ $? -eq 0 ] ; then
+    rm -f conftest conftest.c
+    return 0
+  else
+    rm -f conftest conftest.c
+    return 1
+  fi
+}
+
 stravischeck() {
   cat << EOF > conftest.c
 #include <stdlib.h>
@@ -568,6 +598,24 @@ else
   echo "no"
 fi
 
+printf "checking for st_mtim... "
+st_mtimcheck
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_ST_MTIM" >> pconfig.h
+  echo "yes"
+else
+  echo "no"
+fi
+
+printf "checking for st_mtimespec... "
+st_mtimespeccheck
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_ST_MTIMESPEC" >> pconfig.h
+  echo "yes"
+else
+  echo "no"
+fi
+
 printf "checking for stravis... "
 stravischeck
 if [ $? -eq 0 ] ; then
diff --git a/portable.h b/portable.h
@@ -113,9 +113,9 @@
 #endif /* !HAVE_TIMERSUB */
 
 /* struct stat compatibility */
-#ifdef __APPLE__
+#if !defined(HAVE_ST_MTIM) && defined(HAVE_ST_MTIMESPEC)
 #define st_mtim	st_mtimespec
-#endif /* __APPLE__ */
+#endif /* !HAVE_ST_MTIM && HAVE_ST_MTIMESPEC */
 
 /* Cygwin already has a sys_signame but we want to use our own */
 #ifdef __CYGWIN__
@@ -147,6 +147,11 @@
         } while (0)
 #endif /* !__OpenBSD__ */
 
+#if !defined(HAVE_ST_MTIM) && !defined(HAVE_ST_MTIMESPEC)
+#define timespeccmp(tsp, usp, cmp) (tsp) cmp (usp)
+#define st_mtim st_mtime
+#endif /* !HAVE_ST_MTIM && !HAVE_ST_TIMESPEC */
+
 /*
  * Prototypes
  */