github.com/tetratelabs/wazero@v1.2.1/internal/sysfs/open_file.go (about)

     1  //go:build !windows && !js && !illumos && !solaris
     2  
     3  package sysfs
     4  
     5  import (
     6  	"io/fs"
     7  	"os"
     8  	"syscall"
     9  
    10  	"github.com/tetratelabs/wazero/internal/fsapi"
    11  	"github.com/tetratelabs/wazero/internal/platform"
    12  )
    13  
    14  func newOsFile(openPath string, openFlag int, openPerm fs.FileMode, f *os.File) fsapi.File {
    15  	return newDefaultOsFile(openPath, openFlag, openPerm, f)
    16  }
    17  
    18  // OpenFile is like os.OpenFile except it returns syscall.Errno. A zero
    19  // syscall.Errno is success.
    20  func openFile(path string, flag int, perm fs.FileMode) (*os.File, syscall.Errno) {
    21  	f, err := os.OpenFile(path, flag, perm)
    22  	// Note: This does not return a fsapi.File because fsapi.FS that returns
    23  	// one may want to hide the real OS path. For example, this is needed for
    24  	// pre-opens.
    25  	return f, platform.UnwrapOSError(err)
    26  }