Skip to content

Commit 79e14e5

Browse files
committed
chore: some more kotlin native extension utils
1 parent b8fedfc commit 79e14e5

File tree

2 files changed

+20
-5
lines changed
  • backend/native/src

2 files changed

+20
-5
lines changed
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import kotlinx.cinterop.toKString
2-
import platform.posix.getpass
1+
import kotlin.time.Instant
2+
import kotlinx.cinterop.*
3+
import kotlinx.io.files.Path
4+
import platform.posix.*
35

46
actual fun readPassword(prompt: String) = getpass(prompt)?.toKString()
7+
8+
fun getMTime(path: Path): Instant {
9+
memScoped {
10+
val stat = alloc<stat>()
11+
if (lstat(path.toString(), stat.ptr) != 0) {
12+
throw IllegalStateException("Failed to get mtime for $path")
13+
}
14+
return Instant.fromEpochSeconds(stat.st_mtim.tv_sec, stat.st_mtim.tv_nsec)
15+
}
16+
}

backend/native/src/nativeMain/kotlin/io/IO.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import kotlin.test.assertEquals
2-
import kotlinx.io.Buffer
1+
import kotlin.test.*
2+
import kotlinx.io.*
33
import kotlinx.io.files.*
4-
import kotlinx.io.readFloat
54

65
fun buffer() {
76
val buffer = Buffer()
@@ -14,3 +13,7 @@ fun dir() {
1413
println("SystemTemporaryDirectory: $SystemTemporaryDirectory")
1514
SystemFileSystem.list(Path(".")).forEach { println(it) }
1615
}
16+
17+
fun Path.append(data: String) {
18+
SystemFileSystem.sink(this, append = true).buffered().use { f -> f.writeString(data) }
19+
}

0 commit comments

Comments
 (0)