GoPLS Viewer

Home|gopls/internal/fastwalk/fastwalk_dirent_namlen_linux.go
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.
4
5//go:build linux && !appengine
6// +build linux,!appengine
7
8package fastwalk
9
10import (
11    "bytes"
12    "syscall"
13    "unsafe"
14)
15
16func direntNamlen(dirent *syscall.Direntuint64 {
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 {
22        limit = nameBufLen
23    }
24    nameLen := bytes.IndexByte(nameBuf[:limit], 0)
25    if nameLen < 0 {
26        panic("failed to find terminating 0 byte in dirent")
27    }
28    return uint64(nameLen)
29}
30
MembersX
bytes
direntNamlen.BlockStmt.nameBuf
direntNamlen.BlockStmt.nameLen
Members
X