Skip to content

Commit

Permalink
wutdevoptab: Add support for opening files with more flag combinations (
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell authored Jun 20, 2023
1 parent 071345f commit 8df8e18
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libraries/wutdevoptab/devoptab_fsa_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ __wut_fsa_open(struct _reent *r,
fsMode = "w";
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT | O_TRUNC))) {
fsMode = "w+";
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == O_CREAT) && (flags & O_EXCL) == O_EXCL) {
// if O_EXCL is set, we don't need O_TRUNC
fsMode = "w";
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == O_CREAT) && (flags & O_EXCL) == O_EXCL) {
// if O_EXCL is set, we don't need O_TRUNC
fsMode = "w+";
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == (O_CREAT | O_APPEND))) {
fsMode = "a";
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT | O_APPEND))) {
Expand All @@ -45,6 +51,10 @@ __wut_fsa_open(struct _reent *r,
// It's not possible to open a file with write only mode which doesn't truncate the file
// Technically we could read from the file, but our read implementation is blocking this.
fsMode = "r+";
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT))) {
// Cafe OS doesn't have a matching mode for this, so we have to be creative and create the file.
createFileIfNotFound = true;
fsMode = "r+";
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == (O_APPEND))) {
// Cafe OS doesn't have a matching mode for this, so we have to check if the file exists.
failIfFileNotFound = true;
Expand Down

0 comments on commit 8df8e18

Please sign in to comment.