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

Opening a directory with O_CREAT should return EISDIR #23218

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}};
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/fcntl/test_fcntl_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions test/fcntl/test_fcntl_open.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5545,6 +5545,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')

Expand Down
Loading