// 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 isBigEndian {
		return readIntBE([:], ), true
	}
	return readIntLE([:], ), true
}

func readIntBE( []byte,  uintptr) uint64 {
	switch  {
	case 1:
		return uint64([0])
	case 2:
		_ = [1] // bounds check hint to compiler; see golang.org/issue/14808
		return uint64([1]) | uint64([0])<<8
	case 4:
		_ = [3] // bounds check hint to compiler; see golang.org/issue/14808
		return uint64([3]) | uint64([2])<<8 | uint64([1])<<16 | uint64([0])<<24
	case 8:
		_ = [7] // bounds check hint to compiler; see golang.org/issue/14808
		return uint64([7]) | uint64([6])<<8 | uint64([5])<<16 | uint64([4])<<24 |
			uint64([3])<<32 | uint64([2])<<40 | uint64([1])<<48 | uint64([0])<<56
	default:
		panic("syscall: readInt with unsupported size")
	}
}

func readIntLE( []byte,  uintptr) uint64 {
	switch  {
	case 1:
		return uint64([0])
	case 2:
		_ = [1] // bounds check hint to compiler; see golang.org/issue/14808
		return uint64([0]) | uint64([1])<<8
	case 4:
		_ = [3] // bounds check hint to compiler; see golang.org/issue/14808
		return uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24
	case 8:
		_ = [7] // bounds check hint to compiler; see golang.org/issue/14808
		return uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 |
			uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56
	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(), , 
}