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