diff --git a/std/datetime/systime.d b/std/datetime/systime.d index e9f07b5f7..70dc24de6 100644 --- a/std/datetime/systime.d +++ b/std/datetime/systime.d @@ -322,6 +322,25 @@ public: hnsecsToUnixEpoch; } } + else version (OpenBSD) + { + static if (clockType == ClockType.second) + return unixTimeToStdTime(core.stdc.time.time(null)); + else + { + import core.sys.openbsd.time : clock_gettime, CLOCK_REALTIME; + static if (clockType == ClockType.coarse) alias clockArg = CLOCK_REALTIME; + else static if (clockType == ClockType.normal) alias clockArg = CLOCK_REALTIME; + else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME; + else static assert(0, "Previous static if is wrong."); + timespec ts; + if (clock_gettime(clockArg, &ts) != 0) + throw new TimeException("Call to clock_gettime() failed"); + return convert!("seconds", "hnsecs")(ts.tv_sec) + + ts.tv_nsec / 100 + + hnsecsToUnixEpoch; + } + } else version (DragonFlyBSD) { import core.sys.dragonflybsd.time : clock_gettime, CLOCK_REALTIME, diff --git a/std/file.d b/std/file.d index a744916e2..f6afd5243 100644 --- a/std/file.d +++ b/std/file.d @@ -3590,6 +3590,44 @@ else version (DragonFlyBSD) return buffer.assumeUnique; } + else version (OpenBSD) + { + import core.sys.openbsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC_ARGS, KERN_PROC_ARGV; + import core.sys.posix.unistd : getpid; + import std.conv : to; + import std.exception : enforce, errnoEnforce; + import std.process : searchPathFor; + + int[4] mib = [CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV]; + size_t len; + + auto result = sysctl(mib.ptr, mib.length, null, &len, null, 0); + errnoEnforce(result == 0); + + auto argv = new char*[len - 1]; + result = sysctl(mib.ptr, mib.length, argv.ptr, &len, null, 0); + errnoEnforce(result == 0); + + auto argv0 = argv[0]; + if (*argv0 == '/' || *argv0 == '.') + { + import core.sys.posix.stdlib : realpath; + auto absolutePath = realpath(argv0, null); + scope (exit) + { + if (absolutePath) + free(absolutePath); + } + errnoEnforce(absolutePath); + return to!(string)(absolutePath); + } + else + { + auto absolutePath = searchPathFor(to!string(argv0)); + errnoEnforce(absolutePath); + return absolutePath; + } + } else version (Solaris) { import core.sys.posix.unistd : getpid; diff --git a/std/parallelism.d b/std/parallelism.d index 713a28680..9f1a32126 100644 --- a/std/parallelism.d +++ b/std/parallelism.d @@ -994,6 +994,11 @@ uint totalCPUsImpl() @nogc nothrow @trusted import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf; return cast(uint) sysconf(_SC_NPROCESSORS_ONLN); } + else version (OpenBSD) + { + import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf; + return cast(uint) sysconf(_SC_NPROCESSORS_ONLN); + } else version (useSysctlbyname) { version (Darwin) diff --git a/std/process.d b/std/process.d index 877c7876c..551d5d7c5 100644 --- a/std/process.d +++ b/std/process.d @@ -1428,7 +1428,7 @@ version (Windows) @system unittest // Searches the PATH variable for the given executable file, // (checking that it is in fact executable). version (Posix) -private string searchPathFor(scope const(char)[] executable) +package(std) string searchPathFor(scope const(char)[] executable) @safe { import std.algorithm.iteration : splitter; diff --git a/std/stdio.d b/std/stdio.d index af63c5f7a..4d1674cf4 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -79,6 +79,10 @@ else version (NetBSD) { version = GENERIC_IO; } +else version (OpenBSD) +{ + version = GENERIC_IO; +} else version (DragonFlyBSD) { version = GENERIC_IO;