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: 061993b096148afde151c9277db5804eab11a383
parent: 4ff209138921b71c799fdc8b445f8df60cb951d9
author: Brian Callahan <bcallah@openbsd.org>
date:   Fri, 12 Jan 2018 03:09:11 -0500
Check for pledge in configure. Lets oksh build on old versions of OpenBSD.
Mconfigure104++++++++++++--------
Mhistory.c2+-
Mmain.c2+-
Mportable.h40++++----
Mprescue.h11+--
Mreallocarray.c4+-
Msigname.c4+-
Mstrlcat.c4+-
Mstrlcpy.c4+-
Mstrtonum.c4+-
Munvis.c4+-
Mvis.c4+-
12 files changed, 101 insertions(+), 86 deletions(-)
diff --git a/configure b/configure
@@ -36,6 +36,21 @@ EOF
   return 1
 }
 
+pledgecheck() {
+  cat << EOF > conftest.c
+#include <unistd.h>
+int main(void){pledge(NULL,NULL);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
+}
+
 reallocarraycheck() {
   cat << EOF > conftest.c
 #include <stdlib.h>
@@ -285,94 +300,103 @@ cat << EOF > pconfig.h
 
 EOF
 
+printf "checking for pledge... "
+pledgecheck
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_PLEDGE" >> pconfig.h
+  echo "yes"
+else
+  echo "no"
+fi
+
 printf "checking for reallocarray... "
 reallocarraycheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_REALLOCARRAY" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_REALLOCARRAY" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for setresgid... "
 setresgidcheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_SETRESGID" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_SETRESGID" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for setresuid... "
 setresuidcheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_SETRESUID" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_SETRESUID" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for srand_deterministic... "
 sranddeterministiccheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_SRAND_DETERMINISTIC" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_SRAND_DETERMINISTIC" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for stravis... "
 stravischeck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_STRAVIS" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_STRAVIS" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for strlcat... "
 strlcatcheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_STRLCAT" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_STRLCAT" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for strlcpy... "
 strlcpycheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_STRLCPY" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_STRLCPY" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for strtonum... "
 strtonumcheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_STRTONUM" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_STRTONUM" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for strunvis... "
 strunvischeck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_STRUNVIS" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_STRUNVIS" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "checking for sys_signame... "
 signamecheck
-if [ $? -ne 0 ] ; then
-  echo "#define NEED_SIGNAME" >> pconfig.h
-  echo "no"
-else
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_SIGNAME" >> pconfig.h
   echo "yes"
+else
+  echo "no"
 fi
 
 printf "creating Makefile... "
diff --git a/history.c b/history.c
@@ -24,7 +24,7 @@
 
 #include "sh.h"
 
-#if defined(NEED_STRAVIS) || defined(NEED_STRUNVIS)
+#if !defined(HAVE_STRAVIS) || !defined(HAVE_STRUNVIS)
 #include "vis.h"
 #else
 #include <vis.h>
diff --git a/main.c b/main.c
@@ -150,7 +150,7 @@ main(int argc, char *argv[])
 
 	kshname = argv[0];
 
-#ifdef __OpenBSD__
+#ifdef HAVE_PLEDGE
 	if (pledge("stdio rpath wpath cpath fattr flock getpw proc exec tty",
 	    NULL) == -1) {
 		perror("pledge");
diff --git a/portable.h b/portable.h
@@ -74,17 +74,17 @@
 	(y)->tv_nsec = mts.tv_nsec;
 #endif /* __APPLE__ */
 
-#ifdef NEED_SETRESGID
+#ifndef HAVE_SETRESGID
 #define setresgid(x, y, z)	setgid(x); setegid(y); setgid(z)
-#endif /* setresgid */
+#endif /* !HAVE_SETRESGID */
 
-#ifdef NEED_SETRESUID
+#ifndef HAVE_SETRESUID
 #define setresuid(x, y, z)	setuid(x); seteuid(y); setuid(z)
-#endif /* NEED_SETRESUID */
+#endif /* !HAVE_SETRESUID */
 
-#ifdef NEED_SRAND_DETERMINISTIC
+#ifndef HAVE_SRAND_DETERMINISTIC
 #define srand_deterministic(x)	srand(x)
-#endif /* NEED_SRAND_DETERMINISTIC */
+#endif /* !HAVE_SRAND_DETERMINISTIC */
 
 /* struct stat compatibility */
 #ifdef __APPLE__
@@ -118,38 +118,38 @@
  * Prototypes
  */
 
-#ifdef NEED_REALLOCARRAY
+#ifndef HAVE_REALLOCARRAY
 void	 *reallocarray(void *, size_t, size_t);
-#endif /* NEED_REALLOCARRAY */
+#endif /* !HAVE_REALLOCARRAY */
 
-#ifdef NEED_STRAVIS
+#ifndef HAVE_STRAVIS
 int	  stravis(char **, const char *, int);
-#endif /* NEED_STRAVIS */
+#endif /* !HAVE_STRAVIS */
 
-#ifdef NEED_STRLCAT
+#ifndef HAVE_STRLCAT
 size_t	strlcat(char *, const char *, size_t);
-#endif /* NEED_STRLCAT */
+#endif /* !HAVE_STRLCAT */
 
-#ifdef NEED_STRLCPY
+#ifndef HAVE_STRLCPY
 size_t	strlcpy(char *, const char *, size_t);
-#endif /* NEED_STRLCPY */
+#endif /* !HAVE_STRLCPY */
 
-#ifdef NEED_STRTONUM
+#ifndef HAVE_STRTONUM
 long long strtonum(const char *numstr, long long minval, long long maxval,
 		   const char **errstrp);
-#endif /* NEED_STRTONUM */
+#endif /* !HAVE_STRTONUM */
 
-#ifdef NEED_STRUNVIS
+#ifndef HAVE_STRUNVIS
 int	  strunvis(char *, const char *);
-#endif /* NEED_STRUNVIS */
+#endif /* !HAVE_STRUNVIS */
 
 /*
  * Externs
  */
 
-#ifdef NEED_SIGNAME
+#ifndef HAVE_SIGNAME
 extern const char *const sys_signame[NSIG];
-#endif /* NEED_SIGNAME */
+#endif /* !HAVE_SIGNAME */
 
 /*
  * OpenBSD sys/queue.h
diff --git a/prescue.h b/prescue.h
@@ -1,10 +1 @@
-#define NEED_REALLOCARRAY
-#define NEED_SETRESGID
-#define NEED_SETRESUID
-#define NEED_SRAND_DETERMINISTIC
-#define NEED_STRAVIS
-#define NEED_STRLCAT
-#define NEED_STRLCPY
-#define NEED_STRTONUM
-#define NEED_STRUNVIS
-#define NEED_SIGNAME
+/* This file intentionally left blank.  */
diff --git a/reallocarray.c b/reallocarray.c
@@ -17,7 +17,7 @@
 
 #include "pconfig.h"
 
-#ifdef NEED_REALLOCARRAY
+#ifndef HAVE_REALLOCARRAY
 
 #include <sys/types.h>
 #include <errno.h>
@@ -41,4 +41,4 @@ reallocarray(void *optr, size_t nmemb, size_t size)
 	return realloc(optr, size * nmemb);
 }
 
-#endif /* NEED_REALLOCARRAY */
+#endif /* !HAVE_REALLOCARRAY */
diff --git a/signame.c b/signame.c
@@ -30,7 +30,7 @@
 
 #include "pconfig.h"
 
-#ifdef NEED_SIGNAME
+#ifndef HAVE_SIGNAME
 
 #include <signal.h>
 #include <unistd.h>
@@ -71,4 +71,4 @@ const char *const sys_signame[NSIG] = {
 	"THR",		/* SIGTHR */
 };
 
-#endif /* NEED_SIGNAME */
+#endif /* !HAVE_SIGNAME */
diff --git a/strlcat.c b/strlcat.c
@@ -18,7 +18,7 @@
 
 #include "pconfig.h"
 
-#ifdef NEED_STRLCAT
+#ifndef HAVE_STRLCAT
 
 #include <sys/types.h>
 #include <string.h>
@@ -58,4 +58,4 @@ strlcat(char *dst, const char *src, size_t dsize)
 	return(dlen + (src - osrc));	/* count does not include NUL */
 }
 
-#endif /* NEED_STRLCAT */
+#endif /* !HAVE_STRLCAT */
diff --git a/strlcpy.c b/strlcpy.c
@@ -18,7 +18,7 @@
 
 #include "pconfig.h"
 
-#ifdef NEED_STRLCPY
+#ifndef HAVE_STRLCPY
 
 #include <sys/types.h>
 #include <string.h>
@@ -53,4 +53,4 @@ strlcpy(char *dst, const char *src, size_t dsize)
 	return(src - osrc - 1);	/* count does not include NUL */
 }
 
-#endif /* NEED_STRLCPY */
+#endif /* !HAVE_STRLCPY */
diff --git a/strtonum.c b/strtonum.c
@@ -19,7 +19,7 @@
 
 #include "pconfig.h"
 
-#ifdef NEED_STRTONUM
+#ifndef HAVE_STRTONUM
 
 #include <errno.h>
 #include <limits.h>
@@ -68,4 +68,4 @@ strtonum(const char *numstr, long long minval, long long maxval,
 	return (ll);
 }
 
-#endif /* NEED_STRTONUM */
+#endif /* !HAVE_STRTONUM */
diff --git a/unvis.c b/unvis.c
@@ -30,7 +30,7 @@
 
 #include "pconfig.h"
 
-#ifdef NEED_STRUNVIS
+#ifndef HAVE_STRUNVIS
 
 #include <sys/types.h>
 #include <ctype.h>
@@ -247,4 +247,4 @@ strunvis(char *dst, const char *src)
 	return (dst - start);
 }
 
-#endif /* NEED_STRUNVIS */
+#endif /* !HAVE_STRUNVIS */
diff --git a/vis.c b/vis.c
@@ -30,7 +30,7 @@
 
 #include "portable.h"
 
-#ifdef NEED_STRAVIS
+#ifndef HAVE_STRAVIS
 
 #include <sys/types.h>
 #include <errno.h>
@@ -186,4 +186,4 @@ stravis(char **outp, const char *src, int flag)
 	return (len);
 }
 
-#endif /* NEED_STRAVIS */
+#endif /* !HAVE_STRAVIS */