c - 使用未声明的标识符 'O_DIRECT'

标签 c macos

Apple LLVM 版本 10.0.0 (clang-1000.10.44.4)
目标:x86_64-apple-darwin18.0.0

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#define _GNU_SOURCE
#define __USE_GNU 1
#include <fcntl.h>


int main()
{
    int fd = open("./test.txt", O_WRONLY|O_DIRECT);

    close(fd);

    return 0;
}

我使用 clang -o out test.c 得到以下结果:

test.c:14:39: error: use of undeclared identifier 'O_DIRECT'
    int fd = open("./test.txt", O_WRONLY|O_DIRECT);

我该如何解决这个问题?

谢谢。

最佳答案

使用此代码段无法说明您正在尝试做什么,但通常不要在可移植的应用程序中使用非标准内容。

完成任务的可移植方式可能 fsync

关于c - 使用未声明的标识符 'O_DIRECT',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55281353/

相关文章:

c - 升序和降序

c - 从unit8_t缓冲区到结构体的指针类型转换

c - 如何解决黑客等级的楼梯问题

macos - GGTS 3.6.4(OSX 64位)错误-系统属性http.nonProxyHosts已设置为本地

python - 运行时错误 :freeze_support() on Mac

objective-c - OSX 以 root 身份以编程方式启动 launchctl

macos - 如果从今年开始停产,如何使用 Homebrew 软件安装php 5.6?

c - c中的字符串比较

使用类似位图的宏在编译时创建函数

ios - 如何通过命令行在 Xcode 中登录 Apple ID?