Skip to content

Foundation: adjust NSTemporaryDirectory for Windows #1940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
import CoreFoundation

public func NSTemporaryDirectory() -> String {
#if os(Windows)
let cchLength: DWORD = GetTempPathW(0, nil)
var wszPath: [WCHAR] = Array<WCHAR>(repeating: 0, count: Int(cchLength + 1))
guard GetTempPathW(DWORD(wszPath.count), &wszPath) == cchLength else {
precondition(false, "GetTempPathW mutation race")
}
return String(decodingCString: wszPath, as: UTF16.self)
#else
#if canImport(Darwin)
var length: Int = confstr(_CS_DARWIN_USER_TEMP_DIR, nil, 0)
if length > 0 {
Expand All @@ -28,6 +36,7 @@ public func NSTemporaryDirectory() -> String {
}
}
return "/tmp/"
#endif
}

extension String {
Expand Down