Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about readdirnames function #33428

Closed
LiMoMoMo opened this issue Aug 2, 2019 · 2 comments
Closed

Question about readdirnames function #33428

LiMoMoMo opened this issue Aug 2, 2019 · 2 comments

Comments

@LiMoMoMo
Copy link

LiMoMoMo commented Aug 2, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\GoWork
set GOPROXY=
set GORACE=
set GOROOT=C:\tools\go
set GOTMPDIR=
set GOTOOLDIR=C:\tools\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build222429846=/tmp/go-build -gno-record-gcc-switches

GOROOT/src/os/dir_ios.go

func (f *File) readdirnames(n int) (names []string, err error) {
	if f.dirinfo == nil {
		dir, call, errno := f.pfd.OpenDir()
		if errno != nil {
			return nil, wrapSyscallError(call, errno)
		}
		f.dirinfo = &dirInfo{
			dir: dir,
		}
	}
	d := f.dirinfo

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

	names = make([]string, 0, size)
	var dirent syscall.Dirent
	var entptr uintptr
	for len(names) < size {
		if res := readdir_r(d.dir, uintptr(unsafe.Pointer(&dirent)), uintptr(unsafe.Pointer(&entptr))); res != 0 {
			return names, wrapSyscallError("readdir", syscall.Errno(res))
		}
		if entptr == 0 { // EOF
			break
		}
		if dirent.Ino == 0 {
			continue
		}
		name := (*[len(syscall.Dirent{}.Name)]byte)(unsafe.Pointer(&dirent.Name))[:]
		for i, c := range name {
			if c == 0 {
				name = name[:i]
				break
			}
		}
		// Check for useless names before allocating a string.
		if string(name) == "." || string(name) == ".." {
			continue
		}
		names = append(names, string(name))
		runtime.KeepAlive(f)
	}
	if n >= 0 && len(names) == 0 {
		return names, io.EOF
	}
	return names, nil
}

this function only return 100 records when n<=0, even though the children's count is more than 100.

@oiooj oiooj added the Question label Aug 2, 2019
@AlexRouSg
Copy link
Contributor

Duplicate of #33426

@agnivade
Copy link
Contributor

agnivade commented Aug 2, 2019

As @AlexRouSg has said, please redirect your questions to that issue.

@agnivade agnivade closed this as completed Aug 2, 2019
@golang golang locked and limited conversation to collaborators Aug 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants