summaryrefslogtreecommitdiff
path: root/lib/chef/win32/unicode.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/win32/unicode.rb')
-rw-r--r--lib/chef/win32/unicode.rb35
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/chef/win32/unicode.rb b/lib/chef/win32/unicode.rb
index e7399d5255..ed8227ccfd 100644
--- a/lib/chef/win32/unicode.rb
+++ b/lib/chef/win32/unicode.rb
@@ -32,19 +32,36 @@ module FFI
class Pointer
def read_wstring(num_wchars = nil)
if num_wchars.nil?
- # Find the length of the string
- length = 0
- last_char = nil
- while last_char != "\000\000" do
- length += 1
- last_char = self.get_bytes(0,length * 2)[-2..-1]
- end
-
- num_wchars = length
+ num_wchars = get_wstring_len
end
Chef::ReservedNames::Win32::Unicode.wide_to_utf8(self.get_bytes(0, num_wchars*2))
end
+
+ def read_array_of_wstring
+ result = []
+ read_head_ptr = Pointer.new(address)
+ num_wchars = read_head_ptr.get_wstring_len
+ # read until we hit the final null terminating character
+ while num_wchars > 1
+ result << read_head_ptr.read_wstring(num_wchars)
+ read_head_ptr = read_head_ptr + (num_wchars * 2)
+ num_wchars = read_head_ptr.get_wstring_len
+ end
+ result
+ end
+
+ def get_wstring_len
+ # Find the length of the string
+ length = 0
+ last_char = nil
+ while last_char != "\000\000" do
+ length += 1
+ last_char = self.get_bytes(0,length * 2)[-2..-1]
+ end
+
+ length
+ end
end
end