在 Ubuntu(或者说 Linux 的 glibc / POSIX 标准)里,opendir 是 POSIX.1-1988 就规定的函数,并不是一个“某个 Ubuntu 版本才新增”的特性。
具体说明如下:
opendir 来自哪里<dirent.h>open + getdents所有 Ubuntu 版本(包括最早版本)都支持 opendir,例如:
只要使用的是标准 C 库(glibc),就有 opendir。
opendir:一直都有fdopendir:POSIX.1-2008,glibc ≥ 2.4(Ubuntu 6.06 之后基本都有)readdir_r:曾推荐线程安全,现已废弃readdir:一直都有(但不是线程安全)#include <dirent.h>
#include <stdio.h>
int main() {
DIR *dir = opendir(".");
if (!dir) {
perror("opendir");
return 1;
}
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
return 0;
}
✅ opendir 在所有 Ubuntu 版本中都存在
❌ 不存在“某个 Ubuntu 版本才开始支持 opendir”的说法
如果你是想问 fdopendir、scandir 或某个特定目录遍历函数的版本,可以告诉我具体函数名。