package sys
import (
"io"
"os"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/fsapi"
"github.com/tetratelabs/wazero/internal/sysfs"
"github.com/tetratelabs/wazero/sys"
)
type StdinFile struct {
noopStdinFile
io .Reader
}
func (f *StdinFile ) Read (buf []byte ) (int , experimentalsys .Errno ) {
n , err := f .Reader .Read (buf )
return n , experimentalsys .UnwrapOSError (err )
}
type writerFile struct {
noopStdoutFile
w io .Writer
}
func (f *writerFile ) Write (buf []byte ) (int , experimentalsys .Errno ) {
n , err := f .w .Write (buf )
return n , experimentalsys .UnwrapOSError (err )
}
type noopStdinFile struct {
noopStdioFile
}
func (noopStdinFile ) Read ([]byte ) (int , experimentalsys .Errno ) {
return 0 , 0
}
func (noopStdinFile ) Poll (flag fsapi .Pflag , timeoutMillis int32 ) (ready bool , errno experimentalsys .Errno ) {
if flag != fsapi .POLLIN {
return false , experimentalsys .ENOTSUP
}
return true , 0
}
type noopStdoutFile struct {
noopStdioFile
}
func (noopStdoutFile ) Write (buf []byte ) (int , experimentalsys .Errno ) {
return len (buf ), 0
}
type noopStdioFile struct {
experimentalsys .UnimplementedFile
}
func (noopStdioFile ) Stat () (sys .Stat_t , experimentalsys .Errno ) {
return sys .Stat_t {Mode : modeDevice , Nlink : 1 }, 0
}
func (noopStdioFile ) IsDir () (bool , experimentalsys .Errno ) {
return false , 0
}
func (noopStdioFile ) Close () (errno experimentalsys .Errno ) { return }
func (noopStdioFile ) IsNonblock () bool {
return false
}
func (noopStdioFile ) SetNonblock (bool ) experimentalsys .Errno {
return experimentalsys .ENOSYS
}
func (noopStdioFile ) Poll (fsapi .Pflag , int32 ) (ready bool , errno experimentalsys .Errno ) {
return false , experimentalsys .ENOSYS
}
func stdinFileEntry(r io .Reader ) (*FileEntry , error ) {
if r == nil {
return &FileEntry {Name : "stdin" , IsPreopen : true , File : &noopStdinFile {}}, nil
} else if f , ok := r .(*os .File ); ok {
if f , err := sysfs .NewStdioFile (true , f ); err != nil {
return nil , err
} else {
return &FileEntry {Name : "stdin" , IsPreopen : true , File : f }, nil
}
} else {
return &FileEntry {Name : "stdin" , IsPreopen : true , File : &StdinFile {Reader : r }}, nil
}
}
func stdioWriterFileEntry(name string , w io .Writer ) (*FileEntry , error ) {
if w == nil {
return &FileEntry {Name : name , IsPreopen : true , File : &noopStdoutFile {}}, nil
} else if f , ok := w .(*os .File ); ok {
if f , err := sysfs .NewStdioFile (false , f ); err != nil {
return nil , err
} else {
return &FileEntry {Name : name , IsPreopen : true , File : f }, nil
}
} else {
return &FileEntry {Name : name , IsPreopen : true , File : &writerFile {w : w }}, nil
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .