在 Ubuntu(以及一般的 Linux 系统)里,opendir 不是系统调用,而是一个标准 C 库函数(glibc 提供的库函数)。
具体说明如下:
opendir 是什么opendir 定义在 <dirent.h> 中DIR *示例:
#include <dirent.h>
DIR *dir = opendir("/tmp");
虽然 opendir 本身不是系统调用,但它在实现上会调用真正的系统调用,例如:
openat() / open()getdents64()(用于读取目录项)你可以用 strace 看到:
strace ./your_program
会看到类似:
openat(AT_FDCWD, "/tmp", O_RDONLY|O_DIRECTORY) = 3
getdents64(3, ...)
open, read, write, getdents64fopen, opendir, printf✅ opendir:不是系统调用
✅ opendir:C 库函数(glibc)
✅ 它内部会调用系统调用(如 openat、getdents64)
如果你愿意,我也可以帮你对比 opendir / readdir / closedir 和底层系统调用的关系。