Remove an undocumented assumption that O_RDONLY == 0

There's at least one Go platform where that is not true.

Making that assumption without any warning is just a trap for future readers.

Instead, just do the obviously correct thing, per the API documentation.

On macOS, this compiles to _literally exactly the same binary code_.

So, let the compiler be clever so that we don't have to.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2022-09-14 20:18:57 +02:00
parent 7f8a7f376a
commit 924ace221c
1 changed files with 4 additions and 2 deletions

View File

@ -71,8 +71,10 @@ func newLastWriterID() []byte {
// openLock will create the file and its parent directories,
// if necessary.
func openLock(path string, ro bool) (fd int, err error) {
flags := os.O_RDONLY | unix.O_CLOEXEC | os.O_CREATE
if !ro {
flags := unix.O_CLOEXEC | os.O_CREATE
if ro {
flags |= os.O_RDONLY
} else {
flags |= os.O_RDWR
}
fd, err = unix.Open(path, flags, 0o644)