c - uv_fs_open : flags and mode on Windows

标签 c linux windows libuv fcntl

来自official documentation我们有以下 uv_fs_open 签名:

int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, int mode, uv_fs_cb cb);

而且据说相当于open(2) .

来自最权威tutorial我在网上找到了这个(强调我的):

flags and mode are standard Unix flags. libuv takes care of converting to the appropriate Windows flags.

因此,我认为以下语句在 Linux 和 Windows 上都适用:

uv_fs_open(my_loop, my_req,  my_filename, O_RDWR | O_CREAT, S_IRWXU, my_callback);

实际上,它在 Linux 上工作得很好。
无论如何,在 Windows 上我收到以下错误:

'O_RDWR': undeclared identifier
'O_CREAT': undeclared identifier
'S_IRWXU': undeclared identifier

这是预期的结果吗(因此教程是错误的)?
我应该怎么做才能调用适用于两个平台的 uv_fs_open
在 Windows 上使用的flagsmode 的值是多少?

最佳答案

要能够在 Windows 上使用 uv_fs_open,用户必须:

  • 显式包含 fcntl.h,因为 uv-win.h 不包含它(更多详细信息请参阅 this 问题)

  • 使用 _O_CREAT_O_RDWR_ 等代替 O_CREATO_RDWR 和其他 (详情请看官方documentation)

类似的东西适用于模式,有关可用常量的详细信息可以在链接文档中找到。

关于c - uv_fs_open : flags and mode on Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40436832/

相关文章:

c - 对命令行参数进行排序

linux - 通过 SSH 打印

c++ - 在 Linux 中使用 PE 节头

c++ - 从 exe 入口点返回不会终止 Windows 10 上的进程

c++ - 用于定期调用的现代高分辨率定时器

c - 这个结构定义到底是什么意思?

c++ - cUrl 命令 C++ 代码替换

c - 绑定(bind)()失败: Invalid argument

c++ - NodeJS : Native c++ module with multi-threading (openmp)

linux - Native Messaging 主机尝试发送长度为 460151579 字节的消息