github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/sysfs/dir.go (about)

     1  package sysfs
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/tetratelabs/wazero/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  }