Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: define S_IWUSR & S_IRUSR for Windows #42748

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a5e1399
[#41591] define S_IWUSR & S_IRUSR for Windows
ilg-ul Apr 15, 2022
62e3b8f
src: define S_IWUSR & S_IRUSR for Windows
ilg-ul Apr 15, 2022
71fbff0
src: define S_IWUSR & S_IRUSR for Windows
ilg-ul Apr 15, 2022
634f22e
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
fbe9542
src: define fs.constants.S_IWUSR & S_IRUSR for Win
ilg-ul Apr 15, 2022
980862f
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
a44c0ef
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
8443080
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
25ed12a
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
5dfde98
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
cf49526
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
c20af35
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
0a772ee
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 15, 2022
4177c19
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 16, 2022
6f5760b
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 16, 2022
c25f5aa
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 16, 2022
124ef5e
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 16, 2022
a81c032
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 16, 2022
2c546c6
Merge branch 'S_IWUSR' of https://github.com/xpack/node-fork into S_I…
ilg-ul Apr 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6771,7 +6771,11 @@ operations.

The following constants are exported by `fs.constants`.

Not every constant will be available on every operating system.
Not every constant will be available on every operating system;
this is especially important for Windows, where many of the POSIX specific
definitions are not available.
For portable applications it is recommended to check for their presence
before use.

To use more than one constant, use the bitwise OR `|` operator.

Expand Down Expand Up @@ -6824,6 +6828,8 @@ The following constants are meant for use as the `mode` parameter passed to
</tr>
</table>

The definitions are also available on Windows.

##### File copy constants

The following constants are meant for use with [`fs.copyFile()`][].
Expand Down Expand Up @@ -6852,6 +6858,8 @@ The following constants are meant for use with [`fs.copyFile()`][].
</tr>
</table>

The definitions are also available on Windows.

##### File open constants

The following constants are meant for use with `fs.open()`.
Expand Down Expand Up @@ -6946,6 +6954,9 @@ The following constants are meant for use with `fs.open()`.
</tr>
</table>

On Windows, only `O_APPEND`, `O_CREAT`, `O_EXCL`, `O_RDONLY`, `O_RDWR`,
`O_TRUNC`, `O_WRONLY` and `UV_FS_O_FILEMAP` are available.

##### File type constants

The following constants are meant for use with the {fs.Stats} object's
Expand Down Expand Up @@ -6990,6 +7001,9 @@ The following constants are meant for use with the {fs.Stats} object's
</tr>
</table>

On Windows, only `S_IFCHR`, `S_IFDIR`, `S_IFLNK`, `S_IFMT`, and `S_IFREG`,
are available.

##### File mode constants

The following constants are meant for use with the {fs.Stats} object's
Expand Down Expand Up @@ -7050,6 +7064,8 @@ The following constants are meant for use with the {fs.Stats} object's
</tr>
</table>

On Windows, only `S_IRUSR` and `S_IWUSR` are available.

## Notes

### Ordering of callback and promise-based operations
Expand Down
10 changes: 10 additions & 0 deletions src/node_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
#include <dlfcn.h>
#endif

#if defined(_WIN32)
#include <io.h> // _S_IREAD _S_IWRITE
#ifndef S_IRUSR
#define S_IRUSR _S_IREAD
#endif // S_IRUSR
#ifndef S_IWUSR
#define S_IWUSR _S_IWRITE
#endif // S_IWUSR
#endif

#include <cerrno>
#include <csignal>
#include <limits>
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-fs-constants-windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
const common = require('../common');
const fs = require('fs');
const assert = require('assert');

// Check if the two constants accepted by chmod() on Windows are defined.
if (common.isWindows) {
assert.ok(fs.constants.S_IRUSR !== undefined);
assert.ok(fs.constants.S_IWUSR !== undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to use assert.notStrictEqual() here. The "is windows?" guard is better written as:

if (!common.isWindows)
  common.skip('Windows-only test');

Although in its current incarnation it's not really Windows-specific. You could just remove the guard altogether and rename the file.

}