scoop:scoop.platform:0.1.0
src/fs/native_os_string.scoop
Selected production source · src/fs/native_os_string.scoop
1
package scoop.platform.fs3
import scoop.platform.memory.nativeMemoryFree4
import scoop.platform.system.*6
@CLayout7
internal struct NativeOsString(val data: Ptr<Byte>?, val length: Long, val error: Int) {8
@Unsafe9
fun takeString(operation: String, context: OsString? = None): OsString {10
if (error != 0)11
failOperatingSystem(operation, error, context)12
try {13
return copyPlatformString(data!!, length)14
}15
finally {16
nativeMemoryFree(data!!)17
}18
}20
@Unsafe21
fun takeOptionalString(operation: String, context: OsString? = None): OsString? {22
if (error != 0)23
failOperatingSystem(operation, error, context)24
if (data == None)25
return None26
return Some(takeString(operation, context))27
}29
@Unsafe30
fun takePath(operation: String, context: OsString? = None): Path =31
Path.fromOsString(takeString(operation, context))32
}