Skip to content

Commit

Permalink
Opening a directory with O_CREAT should return EISDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane committed Dec 18, 2024
1 parent 4ba4c60 commit f78120e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
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

0 comments on commit f78120e

Please sign in to comment.