scoop:scoop.platform:0.1.0
platform/posix/temporary.scoop
Selected production source · platform/posix/temporary.scoop
1
package scoop.platform.fs3
import scoop.platform.io.*4
import scoop.platform.native.temporaryPathPattern5
import scoop.platform.system.*7
internal fun createPlatformTemporaryPath(base: Path, prefix: String, directory: Boolean): Path {8
val pattern = temporaryPathPattern(base, prefix).toOsString().toByteArray()9
@Unsafe10
{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
else18
pattern[index]19
}20
return writable.withDataPointer {21
pointer,22
_ -> @Unsafe23
{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
}30
}32
@Extern(name = "scoop_platform_path_temporary", captureErrno = true)33
private fun nativePathTemporary(pattern: Ptr<Byte>, directory: Boolean): (Int, Int)