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: d0301f9572a4739b12e551938752ea1195aebb69
parent: 4a538b3310e7a0831570bcba593d0085fa3c3d18
author: Brian Callahan <dodonpachi-github@mailinator.com>
date:   Sun, 17 Sep 2017 17:38:34 -0400
Add timespeccmp and timespecsub to all the portable includes.
Mportable/darwin/darwin.h17+++++++++++++++++
Mportable/freebsd/freebsd.h16++++++++++++++++
Mportable/netbsd/netbsd.h16++++++++++++++++
3 files changed, 49 insertions(+)
diff --git a/portable/darwin/darwin.h b/portable/darwin/darwin.h
@@ -13,5 +13,22 @@
 #define setresgid(x, y, z)	setgid(x); setegid(y); setgid(z)
 #define setresuid(x, y, z)	setuid(x); seteuid(y); setuid(z)
 
+/* From OpenBSD sys/time.h */
+#define timespeccmp(tsp, usp, cmp)                                      \
+        (((tsp)->tv_sec == (usp)->tv_sec) ?                             \
+            ((tsp)->tv_nsec cmp (usp)->tv_nsec) :                       \
+            ((tsp)->tv_sec cmp (usp)->tv_sec))
+
+#define timespecsub(tsp, usp, vsp)                                      \
+        do {                                                            \
+                (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
+                (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
+                if ((vsp)->tv_nsec < 0) {                               \
+                        (vsp)->tv_sec--;                                \
+                        (vsp)->tv_nsec += 1000000000L;                  \
+                }                                                       \
+        } while (0)
+
+/* Functions */
 long long strtonum(const char *numstr, long long minval, long long maxval,
 		   const char **errstrp);
diff --git a/portable/freebsd/freebsd.h b/portable/freebsd/freebsd.h
@@ -9,3 +9,19 @@
 /* Defines */
 #define _PW_NAME_LEN	MAXLOGNAME - 1
 #define srand_deterministic(x)	srand(x)
+
+/* From OpenBSD sys/time.h */
+#define timespeccmp(tsp, usp, cmp)                                      \
+        (((tsp)->tv_sec == (usp)->tv_sec) ?                             \
+            ((tsp)->tv_nsec cmp (usp)->tv_nsec) :                       \
+            ((tsp)->tv_sec cmp (usp)->tv_sec))
+
+#define timespecsub(tsp, usp, vsp)                                      \
+        do {                                                            \
+                (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
+                (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
+                if ((vsp)->tv_nsec < 0) {                               \
+                        (vsp)->tv_sec--;                                \
+                        (vsp)->tv_nsec += 1000000000L;                  \
+                }                                                       \
+        } while (0)
diff --git a/portable/netbsd/netbsd.h b/portable/netbsd/netbsd.h
@@ -6,3 +6,19 @@
 #define setresgid(x, y, z)	setgid(x); setegid(x)
 #define setresuid(x, y, z)	setuid(x); seteuid(x)
 #define srand_deterministic(x)	srand(x)
+
+/* From OpenBSD sys/time.h */
+#define timespeccmp(tsp, usp, cmp)                                      \
+        (((tsp)->tv_sec == (usp)->tv_sec) ?                             \
+            ((tsp)->tv_nsec cmp (usp)->tv_nsec) :                       \
+            ((tsp)->tv_sec cmp (usp)->tv_sec))
+
+#define timespecsub(tsp, usp, vsp)                                      \
+        do {                                                            \
+                (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
+                (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
+                if ((vsp)->tv_nsec < 0) {                               \
+                        (vsp)->tv_sec--;                                \
+                        (vsp)->tv_nsec += 1000000000L;                  \
+                }                                                       \
+        } while (0)