From bc10382ec1b87da16943907ba2d0fbd267af07f0 Mon Sep 17 00:00:00 2001 From: Maya Rashish Date: Sat, 16 Feb 2019 12:29:12 +0200 Subject: Add NetBSD support Mostly picking the same paths as FreeBSD. We need a little special handling for crt files, as netbsd uses its own (and not GCC's) for those, with slightly different names. --- src/os.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/os.cpp') diff --git a/src/os.cpp b/src/os.cpp index 8eb6b34654..c11840b1cf 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -50,11 +50,11 @@ typedef SSIZE_T ssize_t; #endif -#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) #include #endif -#if defined(ZIG_OS_FREEBSD) +#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) #include #endif @@ -78,7 +78,7 @@ static clock_serv_t cclock; #if defined(__APPLE__) && !defined(environ) #include #define environ (*_NSGetEnviron()) -#elif defined(ZIG_OS_FREEBSD) +#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) extern char **environ; #endif @@ -1458,6 +1458,15 @@ Error os_self_exe_path(Buf *out_path) { } buf_resize(out_path, cb - 1); return ErrorNone; +#elif defined(ZIG_OS_NETBSD) + buf_resize(out_path, PATH_MAX); + int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME }; + size_t cb = PATH_MAX; + if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) { + return ErrorUnexpected; + } + buf_resize(out_path, cb - 1); + return ErrorNone; #endif return ErrorFileNotFound; } @@ -1776,7 +1785,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { } -#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { ZigList *libs = reinterpret_cast< ZigList *>(data); if (info->dlpi_name[0] == '/') { @@ -1787,7 +1796,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, #endif Error os_self_exe_shared_libs(ZigList &paths) { -#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) paths.resize(0); dl_iterate_phdr(self_exe_shared_libs_callback, &paths); return ErrorNone; -- cgit v1.2.3