Scoop API

scoop:scoop.platform:0.1.0

platform/posix/temporary.scoop

Selected production source · platform/posix/temporary.scoop

1package scoop.platform.fs
3import scoop.platform.io.*
4import scoop.platform.native.temporaryPathPattern
5import scoop.platform.system.*
7internal fun createPlatformTemporaryPath(base: Path, prefix: String, directory: Boolean): Path {
8 val pattern = temporaryPathPattern(base, prefix).toOsString().toByteArray()
9 @Unsafe
10 {
11 if (pattern.size == Long.MAX_VALUE)
12 throw ArithmeticException()
13 val writable =
14 MutableArray<Byte>(pattern.size + 1L) {
15 index -> if (index == pattern.size)
16 0.toByte()
17 else
18 pattern[index]
19 }
20 return writable.withDataPointer {
21 pointer,
22 _ -> @Unsafe
23 {
24 val(status, error) = nativePathTemporary(pointer, directory)
25 checkNativeStatus(status, error, "create temporary path", Some(base.toOsString()))
26 return@withDataPointer Path.fromOsString(copyNativeString(pointer))
27 }
28 }
29 }
32@Extern(name = "scoop_platform_path_temporary", captureErrno = true)
33private fun nativePathTemporary(pattern: Ptr<Byte>, directory: Boolean): (Int, Int)