Adopted common O_RDONLY/WRONLY/RDWR bit patterns
This should, in theory, be a transparent change for users (https://xkcd.com/1172). The motivation for this change: 1. Basically everyone uses O_RDONLY=0, O_WRONLY=1, O_RDWR=2, so deviating from this ad-hoc standard risks surprising POSIX-familiar users, though may confused POSIX-unfamiliar users. But for the latter, we really shouldn't allow them to fall into the trap that O_RDONLY | O_WRONLY == O_RDWR, because this will not work on basically any other POSIX-like system. 2. I realized one benefit of the POSIX encoding is that it reserves the value 3. Maybe this could be useful in the future? Being able to create a file that neither readable nor writable isn't all that useful... Also, if you really think about the literal meaning of O_RDONLY | O_WRONLY, these are negations. So O_RDONLY | O_WRONLY means you can only write and only read? That sounds like an oxymoron. Of course no one should be relying on these exact values, but these are embedded systems! Someone somewhere is going to hack something together that expects these to be their historically expected value. And we shouldn't make things any harder for them unless there's a good reason.
This commit is contained in:
@@ -123,10 +123,10 @@ enum lfs_type {
|
||||
// File open flags
|
||||
enum lfs_open_flags {
|
||||
// open flags
|
||||
LFS_O_RDONLY = 1, // Open a file as read only
|
||||
LFS_O_RDONLY = 0, // Open a file as read only
|
||||
#ifndef LFS_READONLY
|
||||
LFS_O_WRONLY = 2, // Open a file as write only
|
||||
LFS_O_RDWR = 3, // Open a file as read and write
|
||||
LFS_O_WRONLY = 1, // Open a file as write only
|
||||
LFS_O_RDWR = 2, // Open a file as read and write
|
||||
LFS_O_CREAT = 0x0004, // Create a file if it does not exist
|
||||
LFS_O_EXCL = 0x0008, // Fail if a file already exists
|
||||
LFS_O_TRUNC = 0x0010, // Truncate the existing file to zero size
|
||||
|
||||
Reference in New Issue
Block a user