Fix native implementation
This commit is contained in:
17
src/nativeMain/kotlin/com.infendro.shell/C.kt
Normal file
17
src/nativeMain/kotlin/com.infendro.shell/C.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.infendro.shell
|
||||
|
||||
import kotlinx.cinterop.CPointer
|
||||
import kotlinx.cinterop.refTo
|
||||
import kotlinx.cinterop.toKString
|
||||
import platform.posix.FILE
|
||||
import platform.posix.fgets
|
||||
|
||||
internal fun CPointer<FILE>.readLines(): List<String> {
|
||||
val lines = mutableListOf<String>()
|
||||
val buffer = ByteArray(4096)
|
||||
while (true) {
|
||||
val line = fgets(buffer.refTo(0), buffer.size, this) ?: break
|
||||
lines.add(line.toKString())
|
||||
}
|
||||
return lines
|
||||
}
|
||||
Reference in New Issue
Block a user