File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 10
10
import CoreFoundation
11
11
12
12
public func NSTemporaryDirectory( ) -> String {
13
- #if os(macOS) || os(iOS)
14
- var buf = [ Int8] ( repeating: 0 , count: 100 )
15
- let r = confstr ( _CS_DARWIN_USER_TEMP_DIR, & buf, buf. count)
16
- if r != 0 && r < buf. count {
17
- return String ( cString: buf, encoding: . utf8) !
13
+ #if canImport(Darwin)
14
+ var length : Int = confstr ( _CS_DARWIN_USER_TEMP_DIR, nil , 0 )
15
+ if length > 0 {
16
+ var buffer : [ Int8 ] = Array < Int8 > ( repeating: 0 , count: length)
17
+ length = confstr ( _CS_DARWIN_USER_TEMP_DIR, & buffer, buffer. count)
18
+ if length > 0 && length < buffer. count {
19
+ return String ( cString: buffer, encoding: . utf8) !
20
+ }
18
21
}
19
- #endif
22
+ #endif
20
23
if let tmpdir = ProcessInfo . processInfo. environment [ " TMPDIR " ] {
21
24
if !tmpdir. hasSuffix ( " / " ) {
22
25
return tmpdir + " / "
You can’t perform that action at this time.
0 commit comments