From fcb30a0b67b1bd4acbc3422ff74fac5d031ae1ae Mon Sep 17 00:00:00 2001 From: Sébastien Marie Date: Thu, 29 Jan 2015 08:19:28 +0100 Subject: openbsd support --- src/rt/rust_builtin.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'src/rt') diff --git a/src/rt/rust_builtin.c b/src/rt/rust_builtin.c index 03cd3fd6b88..372ff0f2147 100644 --- a/src/rt/rust_builtin.c +++ b/src/rt/rust_builtin.c @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -47,7 +47,7 @@ extern char **environ; #endif #endif -#if defined(__FreeBSD__) || defined(__linux__) || defined(__ANDROID__) || defined(__DragonFly__) +#if defined(__FreeBSD__) || defined(__linux__) || defined(__ANDROID__) || defined(__DragonFly__) || defined(__OpenBSD__) extern char **environ; #endif @@ -199,6 +199,56 @@ rust_unset_sigprocmask() { int *__dfly_error(void) { return __error(); } #endif +#if defined(__OpenBSD__) +#include +#include +#include + +const char * __load_self() { + static char *self = NULL; + + if (self == NULL) { + int mib[4]; + char **argv = NULL; + size_t argv_len; + + /* initialize mib */ + mib[0] = CTL_KERN; + mib[1] = KERN_PROC_ARGS; + mib[2] = getpid(); + mib[3] = KERN_PROC_ARGV; + + /* request KERN_PROC_ARGV size */ + argv_len = 0; + if (sysctl(mib, 4, NULL, &argv_len, NULL, 0) == -1) + return (NULL); + + /* allocate size */ + if ((argv = malloc(argv_len)) == NULL) + return (NULL); + + /* request KERN_PROC_ARGV */ + if (sysctl(mib, 4, argv, &argv_len, NULL, 0) == -1) { + free(argv); + return (NULL); + } + + /* get realpath if possible */ + if ((argv[0] != NULL) && ((*argv[0] == '.') || (*argv[0] == '/') + || (strstr(argv[0], "/") != NULL))) + + self = realpath(argv[0], NULL); + else + self = NULL; + + /* cleanup */ + free(argv); + } + + return (self); +} +#endif + // // Local Variables: // mode: C++ -- cgit 1.4.1-3-g733a5