Skip to content

Commit 564f624

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

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
@@ -23,6 +23,7 @@ import Darwin.C
2323
#endif
2424
import HummingbirdCore
2525
import NIOCore
26+
import Foundation
2627

2728
/// Access environment variables
2829
public struct Environment: Sendable, Decodable, ExpressibleByDictionaryLiteral {
@@ -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+
ProcessInfo.processInfo.environment.keys.forEach { key in
116+
values[key.lowercased()] = ProcessInfo.processInfo.environment[key]
130117
}
131118
return values
132119
}

0 commit comments

Comments
 (0)