Module: CMUX::IO

Defined in:
lib/cmux/io.rb

Class Method Summary collapse

Class Method Details

.open_tty(filename) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cmux/io.rb', line 3

def self.open_tty(filename)
  buffer = FFI::Buffer.new :pointer, 1

  fd = Library.cmux_open_device filename, buffer
  if fd == -1
    ptr = buffer.read_pointer
    begin
      error = ptr.read_string
    ensure
      Library.cmux_free ptr
    end

    raise error
  end

  FFI::IO.for_fd fd, "r+"
end