src: define O_SYNC, O_DSYNC and O_DIRECT on Windows · nodejs/node@83a7949 · GitHub
Skip to content

Commit 83a7949

Browse files
PickBasaduh95
authored andcommitted
src: define O_SYNC, O_DSYNC and O_DIRECT on Windows
Signed-off-by: Kirill Saied <sayed.kirill@gmail.com> PR-URL: #64707 Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 41c5108 commit 83a7949

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

doc/api/fs.md

Lines changed: 5 additions & 3 deletions

src/node_constants.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,10 +1170,22 @@ void DefineFsConstants(Local<Object> target) {
11701170

11711171
#ifdef O_SYNC
11721172
NODE_DEFINE_CONSTANT(target, O_SYNC);
1173+
#elif UV_FS_O_SYNC != 0
1174+
// Windows lacks the POSIX O_SYNC macro, but libuv maps UV_FS_O_SYNC to
1175+
// FILE_FLAG_WRITE_THROUGH, so expose it under the portable name.
1176+
#define O_SYNC UV_FS_O_SYNC
1177+
NODE_DEFINE_CONSTANT(target, O_SYNC);
1178+
#undef O_SYNC
11731179
#endif
11741180

11751181
#ifdef O_DSYNC
11761182
NODE_DEFINE_CONSTANT(target, O_DSYNC);
1183+
#elif UV_FS_O_DSYNC != 0
1184+
// Windows lacks the POSIX O_DSYNC macro, but libuv maps UV_FS_O_DSYNC to
1185+
// FILE_FLAG_WRITE_THROUGH, so expose it under the portable name.
1186+
#define O_DSYNC UV_FS_O_DSYNC
1187+
NODE_DEFINE_CONSTANT(target, O_DSYNC);
1188+
#undef O_DSYNC
11771189
#endif
11781190

11791191

@@ -1183,6 +1195,12 @@ void DefineFsConstants(Local<Object> target) {
11831195

11841196
#ifdef O_DIRECT
11851197
NODE_DEFINE_CONSTANT(target, O_DIRECT);
1198+
#elif UV_FS_O_DIRECT != 0
1199+
// Windows lacks the POSIX O_DIRECT macro, but libuv maps UV_FS_O_DIRECT to
1200+
// FILE_FLAG_NO_BUFFERING, so expose it under the portable name.
1201+
#define O_DIRECT UV_FS_O_DIRECT
1202+
NODE_DEFINE_CONSTANT(target, O_DIRECT);
1203+
#undef O_DIRECT
11861204
#endif
11871205

11881206
#ifdef O_NONBLOCK

test/parallel/test-fs-constants.js

Lines changed: 10 additions & 1 deletion

0 commit comments

Comments
 (0)