DT_DIR 未定义

发布于 2025-01-04 05:47:59 字数 328 浏览 6 评论 0原文

我想检查 readdir 返回的文件是否是目录。 我尝试使用 DT_DIR 常量(如 man readdir 所说)来执行此操作,但它是未定义的。我应该包含什么文件才能获取它?

现在我使用的

#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>

gcc版本是4.6.1

编译字符串:

gcc a.c --std=c99 -Wall

I want to check if file returned by readdir is directory.
I tried do it using DT_DIR constant (as man readdir says) but it's undefined. What file should I include to get it?

Now I use

#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>

gcc version is 4.6.1

Compilation string:

gcc a.c --std=c99 -Wall

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2025-01-11 05:47:59

您需要定义 _BSD_SOURCE 功能测试宏才能获得这些定义,它们不是标准的,并且 GCC 在编译 C99 时不会定义该宏。

gcc -std=c99 -D_BSD_SOURCE -Wall a.c

You need to have the _BSD_SOURCE feature test macro defined to get those defines, they are not standard, and GCC does not define that macro when compiling for C99.

gcc -std=c99 -D_BSD_SOURCE -Wall a.c
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文