版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32768743/article/details/87120730
配置kotlin native
linuxX64('csappCh10No1') {
binaries {
// Comment the next section to generate Kotlin/Native library (KLIB) instead of executable file:
executable('csappCh10No1App') {
// Change to specify fully qualified name of your application's entry point:
entryPoint = 'csapp.main'
}
}
}
kotlin代码
package csapp
import kotlinx.cinterop.*
import platform.posix.*
fun main() {
val fd1 = open("foo.txt", O_RDONLY, 0)
close(fd1)
val fd2 = open("baz.txt", O_RDONLY, 0)
println("fd2 = $fd2")
exit(0)
}
结果
如果baz.txt
存在,则返回一个小的整数,不存在则返回-1
书中的