Skip to content

Commit a8fe20a

Browse files
committed
windows: Fix insecure CRT warning about getenv.
1 parent 6fee761 commit a8fe20a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

PythonKit/PythonLibrary.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,17 @@ extension PythonLibrary {
284284
}
285285

286286
var value: String? {
287+
#if os(Windows)
288+
var cString: UnsafeMutablePointer<CChar>? = nil
289+
var size: size_t = 0
290+
let result = _dupenv_s(&cString, &size, key)
291+
defer {
292+
if let cString { free(cString) }
293+
}
294+
guard result == 0, let cString else { return nil }
295+
#else
287296
guard let cString = getenv(key) else { return nil }
297+
#endif
288298
let value = String(cString: cString)
289299
guard !value.isEmpty else { return nil }
290300
return value

0 commit comments

Comments
 (0)