From 48ff4764a4a7a0a81fb04bc93a09acf8e1e718f0 Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Fri, 12 Jul 2019 16:00:36 +0200 Subject: [PATCH] Add NetBSD support $ make test cd tests && ../flisp unittest.lsp all tests pass --- flisp.c | 2 ++ llt/dirpath.c | 8 +++++++- llt/dtypes.h | 8 ++++++-- llt/socket.c | 2 +- llt/timefuncs.c | 4 ++-- llt/utf8.c | 5 +++-- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/flisp.c b/flisp.c index 08f5c4b..afcaed2 100644 --- a/flisp.c +++ b/flisp.c @@ -2320,6 +2320,8 @@ static void lisp_init(size_t initial_heapsize) 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 diff --git a/llt/dirpath.c b/llt/dirpath.c index 52172ee..aad77d8 100644 --- a/llt/dirpath.c +++ b/llt/dirpath.c @@ -191,7 +191,7 @@ char *get_exename(char *buf, size_t size) return buf; } -#elif defined(FREEBSD) +#elif defined(FREEBSD) || defined(NETBSD) #include #include @@ -199,9 +199,15 @@ char *get_exename(char *buf, size_t size) { 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; diff --git a/llt/dtypes.h b/llt/dtypes.h index 1bab667..911fb5a 100644 --- a/llt/dtypes.h +++ b/llt/dtypes.h @@ -25,13 +25,15 @@ # define OPENBSD #elif defined(__FreeBSD__) # define FREEBSD +#elif defined(__NetBSD__) +# define NETBSD #elif defined(_WIN32) # define WIN32 #else # 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 # define __LITTLE_ENDIAN LITTLE_ENDIAN # define __BIG_ENDIAN BIG_ENDIAN @@ -193,10 +195,12 @@ typedef u_ptrint_t uptrint_t; #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) diff --git a/llt/socket.c b/llt/socket.c index 3984fb0..375c84a 100644 --- a/llt/socket.c +++ b/llt/socket.c @@ -7,7 +7,7 @@ #include "dtypes.h" -#if defined(MACOSX) +#if defined(MACOSX) || defined(NETBSD) #include #include #include diff --git a/llt/timefuncs.c b/llt/timefuncs.c index 09ddeb8..5d6742f 100644 --- a/llt/timefuncs.c +++ b/llt/timefuncs.c @@ -82,7 +82,7 @@ void timestring(double seconds, char *buffer, size_t len) { 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 @@ void timestring(double seconds, char *buffer, size_t len) #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) { diff --git a/llt/utf8.c b/llt/utf8.c index b8b0456..f8ad3bd 100644 --- a/llt/utf8.c +++ b/llt/utf8.c @@ -15,6 +15,7 @@ #define _XOPEN_SOURCE 700 #include #include +#include #include #include #include @@ -26,9 +27,9 @@ #include #define snprintf _snprintf #else -#if !defined(__FreeBSD__) && !defined(__OpenBSD__) +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) #include -#endif /* __FreeBSD__ && __OpenBSD__ */ +#endif /* __FreeBSD__ && __OpenBSD__ && __NetBSD__ */ #endif #include