简体   繁体   English

uv_fs_open:Windows上的标志和模式

[英]uv_fs_open: flags and mode on Windows

From the official documentation we have the following signature for uv_fs_open : 官方文档中我们有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);

And it is said that it is equivalent to open(2) . 据说它相当于open(2)

From the most accredited tutorial I've found on the web, we have this (emphasis mine): 从我在网上找到的最认可的教程 ,我们有这个(强调我的):

flags and mode are standard Unix flags. flags和mode是标准的Unix标志。 libuv takes care of converting to the appropriate Windows flags . libuv负责转换为适当的Windows标志

Because of that, I thought that the following statement would have worked both on Linux and Windows: 因此,我认为以下声明在Linux和Windows上都有效:

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

Actually, it works just fine on Linux. 实际上,它在Linux上运行得很好。
Anyway, on Windows I receive the following errors: 无论如何,在Windows上我收到以下错误:

'O_RDWR': undeclared identifier 'O_RDWR':未声明的标识符
'O_CREAT': undeclared identifier 'O_CREAT':未声明的标识符
'S_IRWXU': undeclared identifier 'S_IRWXU':未声明的标识符

Is it the expected result (and thus the tutorial is wrong)? 这是预期的结果(因此教程是错误的)?
What should I do to have a call to uv_fs_open that just works on both the platforms? 我该怎么做才能调用uv_fs_open才能在两个平台上运行?
What are the values for flags and mode to be used on Windows? Windows上使用的标志模式的值是什么?

To be able to use uv_fs_open on Windows, users have to: 为了能够在Windows上使用uv_fs_open ,用户必须:

  • include fcntl.h explicitly, because uv-win.h doesn't include it (see this issue for further details) 显式包含fcntl.h ,因为uv-win.h不包含它(有关详细信息,请参阅问题)

  • use _O_CREAT , _O_RDWR_ and so on instead of O_CREAT , O_RDWR and the others (see the official documentation for further details) 使用_O_CREAT_O_RDWR_等代替O_CREATO_RDWR和其他(有关详细信息,请参阅官方文档

Something similar applies to the mode and details on the available constants can be found in the linked documentation. 类似的东西适用于模式 ,可用常量的详细信息可以在链接文档中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM