在 Debian(以及一般的 Linux 系统)里,opendir 不是系统调用,而是一个 C 库函数(glibc 封装函数)。
更准确地说:
opendir 是什么opendir 定义在 <dirent.h>DIR *在 Linux 上,opendir 内部通常会调用以下系统调用之一:
open()(打开目录文件)getdents() / getdents64()(读取目录项)也就是说:
用户程序
└─ opendir() // C 库函数
└─ open() // 系统调用
└─ getdents64()// 系统调用(读目录)
你可以用 strace 验证:
strace ls /tmp
你会看到:
openat()getdents64()但不会直接看到 opendir,因为 opendir 是用户态函数。
opendir 不是系统调用opendir 是 libc 提供的库函数open / getdents64 等系统调用如果你愿意,我也可以帮你画一张“目录读取调用栈”的图,或者对比 opendir vs open 的区别。