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.

package os

import (
	
	
	
	
)
Auxiliary information if the File describes a directory
type dirInfo struct {
	dir uintptr // Pointer to DIR structure from dirent.h
}

func ( *dirInfo) () {
	if .dir == 0 {
		return
	}
	closedir(.dir)
	.dir = 0
}

func ( *File) ( int,  readdirMode) ( []string,  []DirEntry,  []FileInfo,  error) {
	if .dirinfo == nil {
		, ,  := .pfd.OpenDir()
		if  != nil {
			return nil, nil, nil, &PathError{Op: , Path: .name, Err: }
		}
		.dirinfo = &dirInfo{
			dir: ,
		}
	}
	 := .dirinfo

	 := 
	if  <= 0 {
		 = 100
		 = -1
	}

	var  syscall.Dirent
	var  *syscall.Dirent
	for len()+len()+len() <  ||  == -1 {
		if  := readdir_r(.dir, &, &);  != 0 {
			if  == syscall.EINTR {
				continue
			}
			return , , , &PathError{Op: "readdir", Path: .name, Err: }
		}
		if  == nil { // EOF
			break
		}
		if .Ino == 0 {
			continue
		}
		 := (*[len(syscall.Dirent{}.Name)]byte)(unsafe.Pointer(&.Name))[:]
		for ,  := range  {
			if  == 0 {
				 = [:]
				break
			}
Check for useless names before allocating a string.
		if string() == "." || string() == ".." {
			continue
		}
		if  == readdirName {
			 = append(, string())
		} else if  == readdirDirEntry {
			,  := newUnixDirent(.name, string(), dtToType(.Type))
File disappeared between readdir and stat. Treat as if it didn't exist.
				continue
			}
			if  != nil {
				return nil, , nil, 
			}
			 = append(, )
		} else {
			,  := lstat(.name + "/" + string())
File disappeared between readdir + stat. Treat as if it didn't exist.
				continue
			}
			if  != nil {
				return nil, nil, , 
			}
			 = append(, )
		}
		runtime.KeepAlive()
	}

	if  > 0 && len()+len()+len() == 0 {
		return nil, nil, nil, io.EOF
	}
	return , , , nil
}

func ( uint8) FileMode {
	switch  {
	case syscall.DT_BLK:
		return ModeDevice
	case syscall.DT_CHR:
		return ModeDevice | ModeCharDevice
	case syscall.DT_DIR:
		return ModeDir
	case syscall.DT_FIFO:
		return ModeNamedPipe
	case syscall.DT_LNK:
		return ModeSymlink
	case syscall.DT_REG:
		return 0
	case syscall.DT_SOCK:
		return ModeSocket
	}
	return ^FileMode(0)
}
Implemented in syscall/syscall_darwin.go.
go:linkname closedir syscall.closedir
func ( uintptr) ( error)
go:linkname readdir_r syscall.readdir_r