From 6afceb562194c6a46297e4672c5e354d558289e5 Mon Sep 17 00:00:00 2001 From: Nia Waldvogel Date: Fri, 14 Jan 2022 16:38:11 -0500 Subject: [PATCH] os (wasi): fix opening files in read-only mode On wasi, O_RDWR is a bitwise or of read and write mode. As a result, the bit test result was incorrect, and rewrote it to read-write mode. However, the bit tests are not necessary (and upstream Go does not use them). This passes the flags through directly. --- src/os/file_anyos.go | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/os/file_anyos.go b/src/os/file_anyos.go index a60a6f78..ea48e9af 100644 --- a/src/os/file_anyos.go +++ b/src/os/file_anyos.go @@ -1,3 +1,4 @@ +//go:build !baremetal && !js // +build !baremetal,!js // Portions copyright 2009 The Go Authors. All rights reserved. @@ -87,33 +88,7 @@ func (fs unixFilesystem) Remove(path string) error { } func (fs unixFilesystem) OpenFile(path string, flag int, perm FileMode) (FileHandle, error) { - // Map os package flags to syscall flags. - syscallFlag := 0 - if flag&O_RDONLY != 0 { - syscallFlag |= syscall.O_RDONLY - } - if flag&O_WRONLY != 0 { - syscallFlag |= syscall.O_WRONLY - } - if flag&O_RDWR != 0 { - syscallFlag |= syscall.O_RDWR - } - if flag&O_APPEND != 0 { - syscallFlag |= syscall.O_APPEND - } - if flag&O_CREATE != 0 { - syscallFlag |= syscall.O_CREAT - } - if flag&O_EXCL != 0 { - syscallFlag |= syscall.O_EXCL - } - if flag&O_SYNC != 0 { - syscallFlag |= syscall.O_SYNC - } - if flag&O_TRUNC != 0 { - syscallFlag |= syscall.O_TRUNC - } - fp, err := syscall.Open(path, syscallFlag, uint32(perm)) + fp, err := syscall.Open(path, flag, uint32(perm)) return unixFileHandle(fp), handleSyscallError(err) }