github.com/charlievieth/fastwalk@v1.0.3/internal/dirent/dirent_openbsd.go (about)

     1  //go:build openbsd
     2  
     3  package dirent
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  	"unsafe"
     9  )
    10  
    11  func direntIno(buf []byte) (uint64, bool) {
    12  	return readInt(buf, unsafe.Offsetof(syscall.Dirent{}.Fileno), unsafe.Sizeof(syscall.Dirent{}.Fileno))
    13  }
    14  
    15  func direntReclen(buf []byte) (uint64, bool) {
    16  	return readInt(buf, unsafe.Offsetof(syscall.Dirent{}.Reclen), unsafe.Sizeof(syscall.Dirent{}.Reclen))
    17  }
    18  
    19  func direntNamlen(buf []byte) (uint64, bool) {
    20  	return readInt(buf, unsafe.Offsetof(syscall.Dirent{}.Namlen), unsafe.Sizeof(syscall.Dirent{}.Namlen))
    21  }
    22  
    23  func direntType(buf []byte) os.FileMode {
    24  	off := unsafe.Offsetof(syscall.Dirent{}.Type)
    25  	if off >= uintptr(len(buf)) {
    26  		return ^os.FileMode(0) // unknown
    27  	}
    28  	typ := buf[off]
    29  	switch typ {
    30  	case syscall.DT_BLK:
    31  		return os.ModeDevice
    32  	case syscall.DT_CHR:
    33  		return os.ModeDevice | os.ModeCharDevice
    34  	case syscall.DT_DIR:
    35  		return os.ModeDir
    36  	case syscall.DT_FIFO:
    37  		return os.ModeNamedPipe
    38  	case syscall.DT_LNK:
    39  		return os.ModeSymlink
    40  	case syscall.DT_REG:
    41  		return 0
    42  	case syscall.DT_SOCK:
    43  		return os.ModeSocket
    44  	}
    45  	return ^os.FileMode(0) // unknown
    46  }