csapp ch10.1练习题

版权声明:本文为博主原创文章,未经博主允许不得转载。 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
在这里插入图片描述
书中的
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_32768743/article/details/87120730