dsafe: init directory
This commit is contained in:
parent
84bf83a36b
commit
43b30424b1
2 changed files with 31 additions and 0 deletions
20
dsafe/pledge.d
Normal file
20
dsafe/pledge.d
Normal file
|
@ -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);
|
||||||
|
}();
|
||||||
|
}
|
11
dsafe/stderr.d
Normal file
11
dsafe/stderr.d
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Opening stderr in safe D
|
||||||
|
*/
|
||||||
|
|
||||||
|
import std.stdio : File;
|
||||||
|
|
||||||
|
File
|
||||||
|
stderr() @safe
|
||||||
|
{
|
||||||
|
return File("/dev/stderr", "w");
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue