Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created January 7, 2019 14:15
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 gr33n7007h/a85f0213cfdb9a5a716105c347e9d460 to your computer and use it in GitHub Desktop.
Save gr33n7007h/a85f0213cfdb9a5a716105c347e9d460 to your computer and use it in GitHub Desktop.
pipe2
>> module IO::Extensions
| extend Fiddle::Importer
| dlload Fiddle::Handle::DEFAULT
| extern 'int pipe2(int pipefd[2], int flags)'
|
| def self.pipe_2 flags:
| pipefds = [0,0].pack 'i2'
| if pipe2(pipefds, flags).zero?
| pipefds.unpack('i2').map &IO.method(:for_fd)
| else
| raise SystemCallError.new Fiddle.last_error
| end
| end
| end
=> :pipe_2
>>
>> r, w = IO::Extensions.pipe_2 flags: IO::DIRECT
=> [#<IO:fd 8>, #<IO:fd 9>]
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment