1 // Copyright 2009 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.
5 // +build aix darwin dragonfly freebsd hurd js,wasm linux netbsd openbsd solaris
11 // readInt returns the size-bytes unsigned integer in native byte order at offset off.
12 func readInt(b
[]byte, off
, size
uintptr) (u
uint64, ok
bool) {
13 if len(b
) < int(off
+size
) {
17 return readIntBE(b
[off
:], size
), true
19 return readIntLE(b
[off
:], size
), true
22 func readIntBE(b
[]byte, size
uintptr) uint64 {
27 _
= b
[1] // bounds check hint to compiler; see golang.org/issue/14808
28 return uint64(b
[1]) |
uint64(b
[0])<<8
30 _
= b
[3] // bounds check hint to compiler; see golang.org/issue/14808
31 return uint64(b
[3]) |
uint64(b
[2])<<8 |
uint64(b
[1])<<16 |
uint64(b
[0])<<24
33 _
= b
[7] // bounds check hint to compiler; see golang.org/issue/14808
34 return uint64(b
[7]) |
uint64(b
[6])<<8 |
uint64(b
[5])<<16 |
uint64(b
[4])<<24 |
35 uint64(b
[3])<<32 |
uint64(b
[2])<<40 |
uint64(b
[1])<<48 |
uint64(b
[0])<<56
37 panic("syscall: readInt with unsupported size")
41 func readIntLE(b
[]byte, size
uintptr) uint64 {
46 _
= b
[1] // bounds check hint to compiler; see golang.org/issue/14808
47 return uint64(b
[0]) |
uint64(b
[1])<<8
49 _
= b
[3] // bounds check hint to compiler; see golang.org/issue/14808
50 return uint64(b
[0]) |
uint64(b
[1])<<8 |
uint64(b
[2])<<16 |
uint64(b
[3])<<24
52 _
= b
[7] // bounds check hint to compiler; see golang.org/issue/14808
53 return uint64(b
[0]) |
uint64(b
[1])<<8 |
uint64(b
[2])<<16 |
uint64(b
[3])<<24 |
54 uint64(b
[4])<<32 |
uint64(b
[5])<<40 |
uint64(b
[6])<<48 |
uint64(b
[7])<<56
56 panic("syscall: readInt with unsupported size")
60 // ParseDirent parses up to max directory entries in buf,
61 // appending the names to names. It returns the number of
62 // bytes consumed from buf, the number of entries added
63 // to names, and the new names slice.
64 func ParseDirent(buf
[]byte, max
int, names
[]string) (consumed
int, count
int, newnames
[]string) {
67 for max
!= 0 && len(buf
) > 0 {
68 reclen
, ok
:= direntReclen(buf
)
69 if !ok || reclen
> uint64(len(buf
)) {
70 return origlen
, count
, names
74 ino
, ok
:= direntIno(rec
)
78 if ino
== 0 { // File absent in directory.
81 const namoff
= uint64(unsafe
.Offsetof(Dirent
{}.Name
))
82 namlen
, ok
:= direntNamlen(rec
)
83 if !ok || namoff
+namlen
> uint64(len(rec
)) {
86 name
:= rec
[namoff
: namoff
+namlen
]
87 for i
, c
:= range name
{
93 // Check for useless names before allocating a string.
94 if string(name
) == "." ||
string(name
) == ".." {
99 names
= append(names
, string(name
))
101 return origlen
- len(buf
), count
, names