Skip to content

Instantly share code, notes, and snippets.

@rightfold

rightfold/.pm6 Secret

Created January 16, 2016 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/eab266b8157c40ba1037 to your computer and use it in GitHub Desktop.
Save rightfold/eab266b8157c40ba1037 to your computer and use it in GitHub Desktop.
use v6.c;
use NativeCall;
module IO::PipeCreation {
sub native-pipe(CArray[int32] --> int32) is native is symbol("pipe") {*}
sub pipe is export {
my @endpoints := CArray[int32].new;
@endpoints[1] = 0;
fail 'unable to create pipe' if native-pipe(@endpoints) != 0;
my $r = open("/proc/self/fd/@endpoints[0]", :r, :bin);
my $w = open("/proc/self/fd/@endpoints[1]", :w, :bin);
($r, $w);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment