diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-18 00:10:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-18 00:10:31 -0500 |
| commit | 3e586264e5295be87f13c34904ff9b61a95ded16 (patch) | |
| tree | 4f20f7fab5d7a4f754c65c6034240a5396b98a24 /src/os.cpp | |
| parent | 39207fa1d46ccaf55de80e1afd89fbccca6a73e7 (diff) | |
| parent | b93405c24bd3c58f68a272f32fe764a994e7aae6 (diff) | |
| download | zig-3e586264e5295be87f13c34904ff9b61a95ded16.tar.gz zig-3e586264e5295be87f13c34904ff9b61a95ded16.zip | |
Merge pull request #1972 from coypoop/netbsd
Add NetBSD support
Diffstat (limited to 'src/os.cpp')
| -rw-r--r-- | src/os.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
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 <link.h> #endif -#if defined(ZIG_OS_FREEBSD) +#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) #include <sys/sysctl.h> #endif @@ -78,7 +78,7 @@ static clock_serv_t cclock; #if defined(__APPLE__) && !defined(environ) #include <crt_externs.h> #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<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(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<Buf *> &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; |
