diff --git a/dsafe/pledge.d b/dsafe/pledge.d new file mode 100644 index 0000000..3e4d832 --- /dev/null +++ b/dsafe/pledge.d @@ -0,0 +1,20 @@ +/* + * Snippet of code showing how to call OpenBSD's + * pledge() syscall in safe D (or not!) + */ + +int +main(string[] args) @safe +{ + /* if you're not using @safe you can + * remove this ugly lambda thing */ + version (OpenBSD) () @trusted { + import core.sys.openbsd.unistd : pledge; + import std.string : toStringz; + + immutable(char) *promises; + + promises = toStringz("stdio rpath wpath cpath ..."); + pledge(promises, null); + }(); +} diff --git a/dsafe/stderr.d b/dsafe/stderr.d new file mode 100644 index 0000000..2a19dfe --- /dev/null +++ b/dsafe/stderr.d @@ -0,0 +1,11 @@ +/* + * Opening stderr in safe D + */ + +import std.stdio : File; + +File +stderr() @safe +{ + return File("/dev/stderr", "w"); +}