18 lines
460 B
Kotlin
18 lines
460 B
Kotlin
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
|
|
}
|