Skip to content

Follow up for changes requested in #1940 #1941

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 24, 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
15 changes: 9 additions & 6 deletions Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import CoreFoundation

public func NSTemporaryDirectory() -> String {
#if os(macOS) || os(iOS)
var buf = [Int8](repeating: 0, count: 100)
let r = confstr(_CS_DARWIN_USER_TEMP_DIR, &buf, buf.count)
if r != 0 && r < buf.count {
return String(cString: buf, encoding: .utf8)!
#if canImport(Darwin)
var length: Int = confstr(_CS_DARWIN_USER_TEMP_DIR, nil, 0)
if length > 0 {
var buffer: [Int8] = Array<Int8>(repeating: 0, count: length)
length = confstr(_CS_DARWIN_USER_TEMP_DIR, &buffer, buffer.count)
if length > 0 && length < buffer.count {
return String(cString: buffer, encoding: .utf8)!
}
}
#endif
#endif
if let tmpdir = ProcessInfo.processInfo.environment["TMPDIR"] {
if !tmpdir.hasSuffix("/") {
return tmpdir + "/"
Expand Down