jelmew
jelmew

Reputation: 583

Fatal error: glibc detected an invalid stdio handle when using kotlin-native

I was playing around with kotlin-native, trying to open a file. The file is opened and created correctly, however, when printing to the file I get the error "Fatal error: glibc detected an invalid stdio handle

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)"

Am I doig something wrong here? Or is this a kotlin configuration issue? The same code does work in C

import kotlinx.cinterop.*
import platform.posix.*

fun main(args: Array<String>) {
    val home = getenv("HOME")?.toKString() ?: "NONE"
    val fopen: FILE = fopen("$home/checkinTime", "w")?.pointed ?: throw RuntimeException()
    val readValue: CValue<FILE> = fopen.readValue();
    fprintf(readValue,"String")
}

Upvotes: 0

Views: 6525

Answers (1)

Nikolay Igotti
Nikolay Igotti

Reputation: 598

This code does the job:

import kotlinx.cinterop.*
import platform.posix.*

fun main(args: Array<String>) {
    val home = getenv("HOME")?.toKString() ?: "NONE"
    val f = fopen("$home/checkinTime", "w") ?: throw RuntimeException()
    fprintf(f, "String")
    fclose(f)
}

Upvotes: 1

Related Questions