Class: Spoon::FileActions

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method 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), self.class)
  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

Class Method Details

.release(ptr) ⇒ Object



28
29
30
31
# File 'lib/spoon/unix.rb', line 28

def self.release(ptr)
  LibC.posix_spawn_file_actions_destroy(ptr)
  LibC.free(ptr)
end

Instance Method Details

#close(fd) ⇒ Object

Raises:

  • (SystemCallError)


39
40
41
42
43
# File 'lib/spoon/unix.rb', line 39

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)


45
46
47
48
49
# File 'lib/spoon/unix.rb', line 45

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)


33
34
35
36
37
# File 'lib/spoon/unix.rb', line 33

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