Skip to content

Implement NSTemporaryDirectory #242

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 3, 2016
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ import Darwin
import Glibc
#endif

public func NSTemporaryDirectory() -> String {
#if os(OSX) || os(iOS)
var buf = [Int8](count: 100, repeatedValue: 0)
let r = confstr(_CS_DARWIN_USER_TEMP_DIR, &buf, buf.count)
if r != 0 && r < buf.count {
return String(CString: buf, encoding: NSUTF8StringEncoding)!
}
#endif
if let tmpdir = NSProcessInfo.processInfo().environment["TMPDIR"] {
return tmpdir
}
return "/tmp/"
}

internal extension String {

internal var _startOfLastPathComponent : String.CharacterView.Index {
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class TestNSURL : XCTestCase {

}

static let gBaseTemporaryDirectoryPath = "/tmp/" // TODO: NSTemporaryDirectory()
static let gBaseTemporaryDirectoryPath = NSTemporaryDirectory()
static var gBaseCurrentWorkingDirectoryPath : String {
let count = Int(1024) // MAXPATHLEN is platform specific; this is the lowest common denominator for darwin and most linuxes
var buf : [Int8] = Array(count: count, repeatedValue: 0)
Expand Down