diff --git a/src/library_fs.js b/src/library_fs.js index 6ed0734949fa1..5fb60d1fb5aee 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -426,8 +426,8 @@ FS.staticInit(); if (FS.isLink(node.mode)) { return {{{ cDefs.ELOOP }}}; } else if (FS.isDir(node.mode)) { - if (FS.flagsToPermissionString(flags) !== 'r' || // opening for write - (flags & {{{ cDefs.O_TRUNC }}})) { // TODO: check for O_SEARCH? (== search for dir only) + if (FS.flagsToPermissionString(flags) !== 'r' // opening for write + || (flags & ({{{ cDefs.O_TRUNC }}} | {{{ cDefs.O_CREAT }}}))) { // TODO: check for O_SEARCH? (== search for dir only) return {{{ cDefs.EISDIR }}}; } } diff --git a/system/lib/wasmfs/syscalls.cpp b/system/lib/wasmfs/syscalls.cpp index 82e3e9d6e0324..94ad74b6595bd 100644 --- a/system/lib/wasmfs/syscalls.cpp +++ b/system/lib/wasmfs/syscalls.cpp @@ -520,7 +520,7 @@ static __wasi_fd_t doOpen(path::ParsedParent parsed, return -EEXIST; } - if (child->is() && accessMode != O_RDONLY) { + if (child->is() && (accessMode != O_RDONLY || (flags & O_CREAT))) { return -EISDIR; } diff --git a/test/fcntl/test_fcntl_open.c b/test/fcntl/test_fcntl_open.c index 0f48c9c17a974..a34de9ea676a2 100644 --- a/test/fcntl/test_fcntl_open.c +++ b/test/fcntl/test_fcntl_open.c @@ -78,7 +78,7 @@ void test() { if ((flags & O_CREAT) && (flags & O_EXCL)) { assert(!success); assert(errno == EEXIST); - } else if ((flags & O_TRUNC) || i != 0 /*mode != O_RDONLY*/) { + } else if ((flags & O_TRUNC) || i != 0 /*mode != O_RDONLY*/ || (flags & O_CREAT)) { assert(!success); assert(errno == EISDIR); } else { diff --git a/test/fcntl/test_fcntl_open.out b/test/fcntl/test_fcntl_open.out index f510e40657a78..19938d6ca9642 100644 --- a/test/fcntl/test_fcntl_open.out +++ b/test/fcntl/test_fcntl_open.out @@ -19,8 +19,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,1 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,1 @@ -139,8 +139,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,9 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,9 @@ -259,8 +259,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,17 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,17 @@ -379,8 +379,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,25 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,25 diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index 4be81cb9fb3af..b2fd8c7b992c7 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8407 +8408 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index a559385da7f91..cdc91cd424110 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8390 +8392 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index d2e5ea2910cc9..199a0b963f1ab 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9411 +9413 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index 2a12540f0635f..0b2a5d20da7ef 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8373 +8374 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize index 2a12540f0635f..0b2a5d20da7ef 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize @@ -1 +1 @@ -8373 +8374 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index 5f41444ba9dcc..9fa65500fcae8 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8404 +8406 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index 54e18a6e2baed..b92fe18e229cc 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9416 +9417 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index 4be81cb9fb3af..b2fd8c7b992c7 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8407 +8408 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index c3a0b57749871..3eb330568eb87 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7702 +7704 diff --git a/test/test_core.py b/test/test_core.py index 015601b228aa2..01565ae626e6f 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5543,6 +5543,7 @@ def test_fcntl(self): self.add_pre_run("FS.createDataFile('/', 'test', 'abcdef', true, true, false);") self.do_run_in_out_file_test('fcntl/test_fcntl.c') + @also_with_nodefs_both def test_fcntl_open(self): self.do_run_in_out_file_test('fcntl/test_fcntl_open.c')