来自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 上使用的flags 和mode 的值是多少?
最佳答案
要能够在 Windows 上使用 uv_fs_open
,用户必须:
显式包含
fcntl.h
,因为uv-win.h
不包含它(更多详细信息请参阅 this 问题)使用
_O_CREAT
、_O_RDWR_
等代替O_CREAT
、O_RDWR
和其他 (详情请看官方documentation)
类似的东西适用于模式,有关可用常量的详细信息可以在链接文档中找到。
关于c - uv_fs_open : flags and mode on Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40436832/