Skip to content
Snippets Groups Projects
dir_unix.go 1.17 KiB
Newer Older
  • Learn to ignore specific revisions
  • // 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.
    
    
    // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
    
    package os
    
    import (
    
    Russ Cox's avatar
    Russ Cox committed
    	"io"
    
    Caine Tighe's avatar
    Caine Tighe committed
    	blockSize = 4096
    
    func (f *File) readdirnames(n int) (names []string, err error) {
    
    	// If this file has no dirinfo, create one.
    
    	if f.dirinfo == nil {
    		f.dirinfo = new(dirInfo)
    
    		// The buffer must be at least a block long.
    
    		f.dirinfo.buf = make([]byte, blockSize)
    
    	names = make([]string, 0, size) // Empty with room to grow.
    
    		// Refill the buffer if necessary
    		if d.bufp >= d.nbuf {
    
    Russ Cox's avatar
    Russ Cox committed
    			var errno error
    
    			d.nbuf, errno = fixCount(syscall.ReadDirent(f.fd, d.buf))
    
    Russ Cox's avatar
    Russ Cox committed
    			if errno != nil {
    
    				return names, NewSyscallError("readdirent", errno)
    
    Russ Cox's avatar
    Russ Cox committed
    			if d.nbuf <= 0 {
    
    		// Drain the buffer
    
    		var nb, nc int
    
    		nb, nc, names = syscall.ParseDirent(d.buf[d.bufp:d.nbuf], n, names)
    
    		d.bufp += nb
    
    	if n >= 0 && len(names) == 0 {
    
    Russ Cox's avatar
    Russ Cox committed
    		return names, io.EOF
    
    	return names, nil