shithub: femtolisp

Download patch

ref: 48ff4764a4a7a0a81fb04bc93a09acf8e1e718f0
parent: 956fd32a06feed0e9a7285ceb66e781d08aea202
author: Kamil Rytarowski <n54@gmx.com>
date: Fri Jul 12 12:00:36 EDT 2019

Add NetBSD support

$ make test
cd tests && ../flisp unittest.lsp
all tests pass

--- a/flisp.c
+++ b/flisp.c
@@ -2320,6 +2320,8 @@
     set(symbol("*os-name*"), symbol("openbsd"));
 #elif defined(FREEBSD)
     set(symbol("*os-name*"), symbol("freebsd"));
+#elif defined(NETBSD)
+    set(symbol("*os-name*"), symbol("netbsd"));
 #else
     set(symbol("*os-name*"), symbol("unknown"));
 #endif
--- a/llt/dirpath.c
+++ b/llt/dirpath.c
@@ -191,7 +191,7 @@
 
     return buf;
 }
-#elif defined(FREEBSD)
+#elif defined(FREEBSD) || defined(NETBSD)
 #include <sys/types.h>
 #include <sys/sysctl.h>
 
@@ -199,9 +199,15 @@
 {
   int mib[4];
   mib[0] = CTL_KERN;
+#if defined(FREEBSD)
   mib[1] = KERN_PROC;
   mib[2] = KERN_PROC_PATHNAME;
   mib[3] = -1;
+#else
+  mib[1] = KERN_PROC_ARGS;
+  mib[2] = -1;
+  mib[3] = KERN_PROC_PATHNAME;
+#endif
   sysctl(mib, 4, buf, &size, NULL, 0);
  
   return buf;
--- a/llt/dtypes.h
+++ b/llt/dtypes.h
@@ -25,6 +25,8 @@
 #  define OPENBSD
 #elif defined(__FreeBSD__)
 #  define FREEBSD
+#elif defined(__NetBSD__)
+#  define NETBSD
 #elif defined(_WIN32)
 #  define WIN32
 #else
@@ -31,7 +33,7 @@
 #  error "unknown platform"
 #endif
 
-#if defined(OPENBSD) || defined(FREEBSD)
+#if defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
 #if defined(__x86_64__)
 #  define __SIZEOF_POINTER__ 8
 #else
@@ -72,7 +74,7 @@
 #  define BIG_ENDIAN     __BIG_ENDIAN
 #  define PDP_ENDIAN     __PDP_ENDIAN
 #  define BYTE_ORDER     __BYTE_ORDER
-#elif defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD)
+#elif defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
 #  include <machine/endian.h>
 #  define __LITTLE_ENDIAN  LITTLE_ENDIAN
 #  define __BIG_ENDIAN     BIG_ENDIAN
@@ -193,10 +195,12 @@
 
 #define DBL_EPSILON      2.2204460492503131e-16
 #define FLT_EPSILON      1.192092896e-7
+#if !defined(NETBSD)
 #define DBL_MAX          1.7976931348623157e+308
 #define DBL_MIN          2.2250738585072014e-308
 #define FLT_MAX          3.402823466e+38
 #define FLT_MIN          1.175494351e-38
+#endif
 #define LOG2_10          3.3219280948873626
 #define rel_zero(a, b) (fabs((a)/(b)) < DBL_EPSILON)
 #define sign_bit(r) ((*(int64_t*)&(r)) & BIT63)
--- a/llt/socket.c
+++ b/llt/socket.c
@@ -7,7 +7,7 @@
 
 #include "dtypes.h"
 
-#if defined(MACOSX)
+#if defined(MACOSX) || defined(NETBSD)
 #include <sys/time.h>
 #include <sys/select.h>
 #include <sys/types.h>
--- a/llt/timefuncs.c
+++ b/llt/timefuncs.c
@@ -82,7 +82,7 @@
 {
     time_t tme = (time_t)seconds;
 
-#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD)
+#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
     char *fmt = "%c"; /* needed to suppress GCC warning */
     struct tm tm;
 
@@ -106,7 +106,7 @@
 #endif
 }
 
-#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD)
+#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
 extern char *strptime(const char *s, const char *format, struct tm *tm);
 double parsetime(const char *str)
 {
--- a/llt/utf8.c
+++ b/llt/utf8.c
@@ -15,6 +15,7 @@
 #define _XOPEN_SOURCE 700
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
 #include <wchar.h>
@@ -26,9 +27,9 @@
 #include <malloc.h>
 #define snprintf _snprintf
 #else
-#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
 #include <alloca.h>
-#endif /* __FreeBSD__ && __OpenBSD__ */
+#endif /* __FreeBSD__ && __OpenBSD__ && __NetBSD__ */
 #endif
 #include <assert.h>