Skip to content

Commit a6835e0

Browse files
committed
fix: use Foundation.ProcessInfo for environment parsing
- replaces use of `environ` with Foundation
1 parent 56336d7 commit a6835e0

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

Sources/Hummingbird/Environment.swift

+3-16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Darwin.C
2121
#else
2222
#error("Unsupported platform")
2323
#endif
24+
import Foundation
2425
import HummingbirdCore
2526
import NIOCore
2627

@@ -111,22 +112,8 @@ public struct Environment: Sendable, Decodable, ExpressibleByDictionaryLiteral {
111112
/// Construct environment variable map
112113
static func getEnvironment() -> [String: String] {
113114
var values: [String: String] = [:]
114-
let equalSign = Character("=")
115-
#if canImport(Musl)
116-
guard let envp = environ else { return [:] }
117-
#else
118-
let envp = environ
119-
#endif
120-
var idx = 0
121-
122-
while let entry = envp.advanced(by: idx).pointee {
123-
let entry = String(cString: entry)
124-
if let i = entry.firstIndex(of: equalSign) {
125-
let key = String(entry.prefix(upTo: i))
126-
let value = String(entry.suffix(from: i).dropFirst())
127-
values[key.lowercased()] = value
128-
}
129-
idx += 1
115+
for key in ProcessInfo.processInfo.environment.keys {
116+
values[key.lowercased()] = ProcessInfo.processInfo.environment[key]
130117
}
131118
return values
132119
}

0 commit comments

Comments
 (0)