File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,28 @@ package kotlinx.io
6
6
7
7
import kotlinx.cinterop.*
8
8
import platform.posix.*
9
+ import kotlin.random.Random
10
+ import kotlin.system.getTimeMillis
9
11
10
12
actual fun createTempFile (): String {
11
13
val template = " tmp-XXXXXX"
12
14
val path = mktemp(template.cstr) ? : throw IOException (" Filed to create temp file: ${strerror(errno)} " )
15
+ // mktemp don't work on MacOS 13+ (as well as mkstemp), at least the way it's expected.
16
+ if (path.toKString() == " " ) {
17
+ val tmpDir = getenv(" TMPDIR" )?.toKString() ? : getenv(" TMP" )?.toKString() ? : " "
18
+ val rnd = Random (getTimeMillis())
19
+ var path: String
20
+ do {
21
+ path = " $tmpDir /tmp-${rnd.nextInt()} "
22
+ } while (access(path, F_OK ) == 0 )
23
+ return path
24
+ }
13
25
return path.toKString()
14
26
}
15
27
16
28
actual fun deleteFile (path : String ) {
17
29
if (access(path, F_OK ) != 0 ) throw IOException (" File does not exist: $path " )
18
30
if (remove(path) != 0 ) {
19
- throw IOException (" Failed to delete file $path : ${strerror(errno)} " )
31
+ throw IOException (" Failed to delete file $path : ${strerror(errno)?.toKString() } " )
20
32
}
21
33
}
You can’t perform that action at this time.
0 commit comments