// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm) || wasip1

package syscall

import (
	
	
	
	
)

// readInt returns the size-bytes unsigned integer in native byte order at offset off.
func readInt( []byte, ,  uintptr) ( uint64,  bool) {
	if len() < int(+) {
		return 0, false
	}
	if goarch.BigEndian {
		return readIntBE([:], ), true
	}
	return readIntLE([:], ), true
}

func readIntBE( []byte,  uintptr) uint64 {
	switch  {
	case 1:
		return uint64([0])
	case 2:
		return uint64(byteorder.BeUint16())
	case 4:
		return uint64(byteorder.BeUint32())
	case 8:
		return uint64(byteorder.BeUint64())
	default:
		panic("syscall: readInt with unsupported size")
	}
}

func readIntLE( []byte,  uintptr) uint64 {
	switch  {
	case 1:
		return uint64([0])
	case 2:
		return uint64(byteorder.LeUint16())
	case 4:
		return uint64(byteorder.LeUint32())
	case 8:
		return uint64(byteorder.LeUint64())
	default:
		panic("syscall: readInt with unsupported size")
	}
}

// ParseDirent parses up to max directory entries in buf,
// appending the names to names. It returns the number of
// bytes consumed from buf, the number of entries added
// to names, and the new names slice.
func ( []byte,  int,  []string) ( int,  int,  []string) {
	 := len()
	 = 0
	for  != 0 && len() > 0 {
		,  := direntReclen()
		if ! ||  > uint64(len()) {
			return , , 
		}
		 := [:]
		 = [:]
		,  := direntIno()
		if ! {
			break
		}
		// See src/os/dir_unix.go for the reason why this condition is
		// excluded on wasip1.
		if  == 0 && runtime.GOOS != "wasip1" { // File absent in directory.
			continue
		}
		const  = uint64(unsafe.Offsetof(Dirent{}.Name))
		,  := direntNamlen()
		if ! || + > uint64(len()) {
			break
		}
		 := [ : +]
		for ,  := range  {
			if  == 0 {
				 = [:]
				break
			}
		}
		// Check for useless names before allocating a string.
		if string() == "." || string() == ".." {
			continue
		}
		--
		++
		 = append(, string())
	}
	return  - len(), , 
}