在 POSIX 系统中使用 open() 和 read() 系统调用列出目录的文件

问题描述

我想知道如何做到这一点。我已经尝试了几件事,但似乎没有什么对我有用。我不想使用 opendir() 系统调用,也不想使用 readdir() 系统调用。你能告诉我怎么做吗,因为我得到了垃圾值。我想列出文件夹内的文件。我从这段代码获取了存储在缓冲区中的垃圾值。

import { createApp } from 'vue'
import App from './App.vue'

console.log('Hello')

createApp(App).mount('#app')

解决方法

你不能这样做。内核只允许在带有特殊选项的目录上使用 fillna(df) ,而根本不允许在目录上使用 open。您必须使用 readopendir

(在幕后,readdir 使用我提到的那些特殊选项调用 opendir,而 open 调用私有系统调用 readdir。参见 https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/opendir.chttps://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/readdir.c . 不建议您自己执行此操作。)