1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 func direntNamlen(dirent *syscall.Dirent) uint64 {
17 const fixedHdr = uint16(unsafe.Offsetof(syscall.Dirent{}.Name))
18 nameBuf := (*[unsafe.Sizeof(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]))
19 const nameBufLen = uint16(len(nameBuf))
20 limit := dirent.Reclen - fixedHdr
21 if limit > nameBufLen {
24 nameLen := bytes.IndexByte(nameBuf[:limit], 0)
26 panic("failed to find terminating 0 byte in dirent")
28 return uint64(nameLen)