Class: ChildProcess::Unix::PosixSpawnProcess::Envp

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

Overview

Argv

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Envp



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/childprocess/unix/posix_spawn_process.rb', line 110

def initialize(env)
  @ptrs = env.map do |key, val|
    next if val.nil?

    if key =~ /=|\0/ || val.include?("\0")
      raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.inspect}"
    end

    FFI::MemoryPointer.from_string("#{key}=#{val}")
  end.compact

  @ptrs << FFI::Pointer.new(0)
end

Instance Method Details

#to_ptrObject



124
125
126
127
128
129
# File 'lib/childprocess/unix/posix_spawn_process.rb', line 124

def to_ptr
  env = FFI::MemoryPointer.new(:pointer, @ptrs.size)
  env.put_array_of_pointer(0, @ptrs)

  env
end