github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/sysfs/dir.go (about)

     1  package sysfs
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/wasilibs/wazerox/experimental/sys"
     7  )
     8  
     9  func adjustReaddirErr(f sys.File, isClosed bool, err error) sys.Errno {
    10  	if err == io.EOF {
    11  		return 0 // e.g. Readdir on darwin returns io.EOF, but linux doesn't.
    12  	} else if errno := sys.UnwrapOSError(err); errno != 0 {
    13  		errno = dirError(f, isClosed, errno)
    14  		// Comply with errors allowed on sys.File Readdir
    15  		switch errno {
    16  		case sys.EINVAL: // os.File Readdir can return this
    17  			return sys.EBADF
    18  		case sys.ENOTDIR: // dirError can return this
    19  			return sys.EBADF
    20  		}
    21  		return errno
    22  	}
    23  	return 0
    24  }