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 {
4242 }
4343
4444 open var environment : [ String : String ] {
45- let equalSign = Int32 ( UInt8 ( ascii: " = " ) )
45+ let equalSign = Character ( " = " )
46+ let strEncoding = String . defaultCStringEncoding
47+ let envp = _CFEnviron ( )
4648 var env : [ String : String ] = [ : ]
4749 var idx = 0
48- let envp = _CFEnviron ( )
4950
5051 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
6256 }
6357 idx += 1
6458 }
You can’t perform that action at this time.
0 commit comments