RosettaCodeData/Task/Use-another-language-to-call-a-function/Kotlin/use-another-language-to-call-a-function-1.kotlin
2023-07-01 13:44:08 -04:00

14 lines
427 B
Text

// Kotlin Native v0.6
import kotlinx.cinterop.*
import platform.posix.*
fun query(data: CPointer<ByteVar>, length: CPointer<size_tVar>): Int {
val s = "Here am I"
val strLen = s.length
val bufferSize = length.pointed.value
if (strLen > bufferSize) return 0 // buffer not large enough
for (i in 0 until strLen) data[i] = s[i].toByte()
length.pointed.value = strLen.signExtend<size_t>()
return 1
}