Skip to content

Commit 8df8e18

Browse files
authored
wutdevoptab: Add support for opening files with more flag combinations (#322)
1 parent 071345f commit 8df8e18

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

libraries/wutdevoptab/devoptab_fsa_open.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ __wut_fsa_open(struct _reent *r,
3535
fsMode = "w";
3636
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT | O_TRUNC))) {
3737
fsMode = "w+";
38+
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == O_CREAT) && (flags & O_EXCL) == O_EXCL) {
39+
// if O_EXCL is set, we don't need O_TRUNC
40+
fsMode = "w";
41+
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == O_CREAT) && (flags & O_EXCL) == O_EXCL) {
42+
// if O_EXCL is set, we don't need O_TRUNC
43+
fsMode = "w+";
3844
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == (O_CREAT | O_APPEND))) {
3945
fsMode = "a";
4046
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT | O_APPEND))) {
@@ -45,6 +51,10 @@ __wut_fsa_open(struct _reent *r,
4551
// It's not possible to open a file with write only mode which doesn't truncate the file
4652
// Technically we could read from the file, but our read implementation is blocking this.
4753
fsMode = "r+";
54+
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT))) {
55+
// Cafe OS doesn't have a matching mode for this, so we have to be creative and create the file.
56+
createFileIfNotFound = true;
57+
fsMode = "r+";
4858
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == (O_APPEND))) {
4959
// Cafe OS doesn't have a matching mode for this, so we have to check if the file exists.
5060
failIfFileNotFound = true;

0 commit comments

Comments
 (0)