Scoop API

scoop:scoop.platform:0.1.0

src/fs/native_os_string.scoop

Selected production source · src/fs/native_os_string.scoop

1package scoop.platform.fs
3import scoop.platform.memory.nativeMemoryFree
4import scoop.platform.system.*
6@CLayout
7internal struct NativeOsString(val data: Ptr<Byte>?, val length: Long, val error: Int) {
8 @Unsafe
9 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 @Unsafe
21 fun takeOptionalString(operation: String, context: OsString? = None): OsString? {
22 if (error != 0)
23 failOperatingSystem(operation, error, context)
24 if (data == None)
25 return None
26 return Some(takeString(operation, context))
27 }
29 @Unsafe
30 fun takePath(operation: String, context: OsString? = None): Path =
31 Path.fromOsString(takeString(operation, context))