skypjack skypjack - 1 year ago 181
C Question

uv_fs_open: flags and mode on Windows

From the official documentation we have the following signature for


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

From the most accredited tutorial I've found on the web, we have this (emphasis mine):

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

Because of that, I thought that the following statement would have worked both on Linux and 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.

Anyway, on Windows I receive the following errors:

'O_RDWR': undeclared identifier

'O_CREAT': undeclared identifier

'S_IRWXU': undeclared identifier

Is it the expected result (and thus the tutorial is wrong)?

What should I do to have a call to
that just works on both the platforms?

What are the values for flags and mode to be used on Windows?

Answer Source

To be able to use uv_fs_open on Windows, users have to:

  • include fcntl.h explicitly, because uv-win.h doesn't include it (see this issue for further details)

  • use _O_CREAT, _O_RDWR_ and so on instead of O_CREAT, O_RDWR and the others (see the official documentation for further details)

Something similar applies to the mode and details on the available constants can be found in the linked documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download