github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/sysfs/oflag.go (about) 1 package sysfs 2 3 import ( 4 "os" 5 6 "github.com/tetratelabs/wazero/experimental/sys" 7 ) 8 9 // toOsOpenFlag converts the input to the flag parameter of os.OpenFile 10 func toOsOpenFlag(oflag sys.Oflag) (flag int) { 11 // First flags are exclusive 12 switch oflag & (sys.O_RDONLY | sys.O_RDWR | sys.O_WRONLY) { 13 case sys.O_RDONLY: 14 flag |= os.O_RDONLY 15 case sys.O_RDWR: 16 flag |= os.O_RDWR 17 case sys.O_WRONLY: 18 flag |= os.O_WRONLY 19 } 20 21 // Run down the flags defined in the os package 22 if oflag&sys.O_APPEND != 0 { 23 flag |= os.O_APPEND 24 } 25 if oflag&sys.O_CREAT != 0 { 26 flag |= os.O_CREATE 27 } 28 if oflag&sys.O_EXCL != 0 { 29 flag |= os.O_EXCL 30 } 31 if oflag&sys.O_SYNC != 0 { 32 flag |= os.O_SYNC 33 } 34 if oflag&sys.O_TRUNC != 0 { 35 flag |= os.O_TRUNC 36 } 37 return withSyscallOflag(oflag, flag) 38 }