4 ms·
Looking at the reworked parseMode API some more and it looks like a total mess. Original code would only accept one of these modes: "r", "w", "wt", "wa", "rw",
by canucker2016 4y ago
Looking at the reworked parseMode API some more and it looks like a total mess.
Original code would only accept one of these modes: "r", "w", "wt", "wa", "rw", "rwt".
Anything else, and you'll get an IllegalArgumentException exception.
which matches the docs:
from https://developer.android.com/reference/android/os/ParcelFileDescriptor#parseMode(java.lang.String) https://developer.android.com/reference/android/os/ParcelFil...
Parameters
mode String: The string representation of the file mode. Can be "r", "w", "wt", "wa", "rw" or "rwt".
Throws
IllegalArgumentException if the given string does not match a known file mode.
----
The modified parseMode code will only throw the IllegalArgumentException if the mode string does NOT start with "rw", "w", or "r".
You can append any other character(s) to the mode string ("a", "t", "x", "y", "z", your fav emoji char), and you won't get an IllegalArgumentException exception
now.
I wonder what happens when open() gets a mode flag with both "a" and "t" set?
parseMode API contract thrown out the window...
- masklinn 4y ago> I wonder what happens when open() gets a mode flag with both "a" and "t" set? Nothing I expect. O_TRUNC and O_APPEND are not incompatible, O_APPEND is just redundant (because by definition if you truncate the file you're writing at its end). macOS certainly doesn't seem to care when I do it.
- cesarb 4y ago> O_APPEND is just redundant (because by definition if you truncate the file you're writing at its end). No, O_APPEND is not redundant with O_TRUNC. When you use O_APPEND, you also have the extra behavior that every write goes to the end of the file, instead of the current position; this is important when more than one process is writing to the same file.