mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
Implement missing OpenBSD ports in phobos
This commit is contained in:
parent
d5412f71cc
commit
c6c8b12852
5 changed files with 67 additions and 1 deletions
|
@ -322,6 +322,25 @@ public:
|
||||||
hnsecsToUnixEpoch;
|
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)
|
else version (DragonFlyBSD)
|
||||||
{
|
{
|
||||||
import core.sys.dragonflybsd.time : clock_gettime, CLOCK_REALTIME,
|
import core.sys.dragonflybsd.time : clock_gettime, CLOCK_REALTIME,
|
||||||
|
|
38
std/file.d
38
std/file.d
|
@ -3590,6 +3590,44 @@ else version (DragonFlyBSD)
|
||||||
|
|
||||||
return buffer.assumeUnique;
|
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)
|
else version (Solaris)
|
||||||
{
|
{
|
||||||
import core.sys.posix.unistd : getpid;
|
import core.sys.posix.unistd : getpid;
|
||||||
|
|
|
@ -994,6 +994,11 @@ uint totalCPUsImpl() @nogc nothrow @trusted
|
||||||
import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf;
|
import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf;
|
||||||
return cast(uint) sysconf(_SC_NPROCESSORS_ONLN);
|
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)
|
else version (useSysctlbyname)
|
||||||
{
|
{
|
||||||
version (Darwin)
|
version (Darwin)
|
||||||
|
|
|
@ -1428,7 +1428,7 @@ version (Windows) @system unittest
|
||||||
// Searches the PATH variable for the given executable file,
|
// Searches the PATH variable for the given executable file,
|
||||||
// (checking that it is in fact executable).
|
// (checking that it is in fact executable).
|
||||||
version (Posix)
|
version (Posix)
|
||||||
private string searchPathFor(scope const(char)[] executable)
|
package(std) string searchPathFor(scope const(char)[] executable)
|
||||||
@safe
|
@safe
|
||||||
{
|
{
|
||||||
import std.algorithm.iteration : splitter;
|
import std.algorithm.iteration : splitter;
|
||||||
|
|
|
@ -79,6 +79,10 @@ else version (NetBSD)
|
||||||
{
|
{
|
||||||
version = GENERIC_IO;
|
version = GENERIC_IO;
|
||||||
}
|
}
|
||||||
|
else version (OpenBSD)
|
||||||
|
{
|
||||||
|
version = GENERIC_IO;
|
||||||
|
}
|
||||||
else version (DragonFlyBSD)
|
else version (DragonFlyBSD)
|
||||||
{
|
{
|
||||||
version = GENERIC_IO;
|
version = GENERIC_IO;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue