Class: Spoon::FileActions

Inherits:
Object
  • Object
show all
Defined in:
lib/spoon/unix.rb

Defined Under Namespace

Classes: Releaser

Constant Summary collapse

SIZE =
FFI::Platform.mac? ? FFI.type_size(:pointer) : 128

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileActions

Returns a new instance of FileActions.

Raises:

  • (SystemCallError)


22
23
24
25
26
# File 'lib/spoon/unix.rb', line 22

def initialize
  @pointer =  FFI::AutoPointer.new(LibC.malloc(SIZE), Releaser)
  error = LibC.posix_spawn_file_actions_init(@pointer)
  raise SystemCallError.new("posix_file_actions_init", error) unless error == 0
end

Instance Attribute Details

#pointerObject (readonly)

Returns the value of attribute pointer.



19
20
21
# File 'lib/spoon/unix.rb', line 19

def pointer
  @pointer
end

Instance Method Details

#close(fd) ⇒ Object

Raises:

  • (SystemCallError)


41
42
43
44
45
# File 'lib/spoon/unix.rb', line 41

def close(fd)
  error = LibC.posix_spawn_file_actions_addclose(@pointer, fd)
  raise SystemCallError.new("posix_file_actions_addclose", error) unless error == 0
  self
end

#dup2(fd, newfd) ⇒ Object

Raises:

  • (SystemCallError)


47
48
49
50
51
# File 'lib/spoon/unix.rb', line 47

def dup2(fd, newfd)
  error = LibC.posix_spawn_file_actions_adddup2(@pointer, fd, newfd)
  raise SystemCallError.new("posix_file_actions_adddup2", error) unless error == 0
  self
end

#open(fd, path, oflag, mode) ⇒ Object

Raises:

  • (SystemCallError)


35
36
37
38
39
# File 'lib/spoon/unix.rb', line 35

def open(fd, path, oflag, mode)
  error = LibC.posix_spawn_file_actions_addopen(@pointer, fd, path, oflag, mode)
  raise SystemCallError.new("posix_file_actions_addopen", error) unless error == 0
  self
end