File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -42,23 +42,17 @@ open class ProcessInfo: NSObject {
42
42
}
43
43
44
44
open var environment : [ String : String ] {
45
- let equalSign = Int32 ( UInt8 ( ascii: " = " ) )
45
+ let equalSign = Character ( " = " )
46
+ let strEncoding = String . defaultCStringEncoding
47
+ let envp = _CFEnviron ( )
46
48
var env : [ String : String ] = [ : ]
47
49
var idx = 0
48
- let envp = _CFEnviron ( )
49
50
50
51
while let entry = envp. advanced ( by: idx) . pointee {
51
- if let value = strchr ( entry, equalSign) {
52
- let keyLen = entry. distance ( to: value)
53
- guard keyLen > 0 else {
54
- continue
55
- }
56
- if let key = NSString ( bytes: entry, length: keyLen, encoding: String . Encoding. utf8. rawValue) {
57
- env [ key. _swiftObject] = String ( cString: value. advanced ( by: 1 ) )
58
- }
59
- } else {
60
- let key = String ( cString: entry)
61
- env [ key] = " "
52
+ if let entry = String ( cString: entry, encoding: strEncoding) , let i = entry. index ( of: equalSign) {
53
+ let key = String ( entry. prefix ( upTo: i) )
54
+ let value = String ( entry. suffix ( from: i) . dropFirst ( ) )
55
+ env [ key] = value
62
56
}
63
57
idx += 1
64
58
}
You can’t perform that action at this time.
0 commit comments