Skip to content
Browse files

Move FFI-based code out of common/env.rb into platform/env.rb.

  • Loading branch information...
1 parent 77994af commit d4eba3d4de46fdeea826c7e7a07e2a2443df3704 @headius headius committed Feb 22, 2011
Showing with 28 additions and 23 deletions.
  1. +1 −23 kernel/common/env.rb
  2. +27 −0 kernel/platform/env.rb
View
24 kernel/common/env.rb
@@ -223,29 +223,7 @@ def to_a
end
def to_hash
- env = environ()
- ptr_size = FFI.type_size FFI.find_type(:pointer)
-
- i = 0
-
- hash = {}
-
- offset = 0
- cur = env + offset
-
- until cur.read_pointer.null?
- entry = cur.read_pointer.read_string
- key, value = entry.split '=', 2
- value.taint if value
- key.taint if key
-
- hash[key] = value
-
- offset += ptr_size
- cur = env + offset
- end
-
- hash
+ return environ_as_hash()
end
def update(other, &block)
View
27 kernel/platform/env.rb
@@ -7,5 +7,32 @@ module EnvironmentAccess
attach_function :setenv, [:string, :string, :int], :int
attach_function :unsetenv, [:string], :int
attach_function :environ, 'ffi_environ', [], :pointer
+
+ def environ_as_hash
+ env = environ()
+ ptr_size = FFI.type_size FFI.find_type(:pointer)
+
+ i = 0
+
+ hash = {}
+
+ offset = 0
+ cur = env + offset
+
+ until cur.read_pointer.null?
+ entry = cur.read_pointer.read_string
+ key, value = entry.split '=', 2
+ value.taint if value
+ key.taint if key
+
+ hash[key] = value
+
+ offset += ptr_size
+ cur = env + offset
+ end
+
+ hash
+ end
+ module_function :environ_as_hash
end
end

0 comments on commit d4eba3d

Please sign in to comment.
Something went wrong with that request. Please try again.