2010-04-02 02:11:17 -06:00
|
|
|
// 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
|
|
|
|
|
2016-08-14 10:39:00 -06:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (file *File) readdir(n int) (fi []FileInfo, err error) {
|
|
|
|
if file == nil {
|
|
|
|
return nil, syscall.EINVAL
|
|
|
|
}
|
|
|
|
if !file.isdir() {
|
|
|
|
return nil, &PathError{"Readdir", file.name, syscall.ENOTDIR}
|
|
|
|
}
|
|
|
|
if !file.dirinfo.isempty && file.fd == syscall.InvalidHandle {
|
|
|
|
return nil, syscall.EINVAL
|
|
|
|
}
|
|
|
|
wantAll := n <= 0
|
|
|
|
size := n
|
|
|
|
if wantAll {
|
|
|
|
n = -1
|
|
|
|
size = 100
|
|
|
|
}
|
|
|
|
fi = make([]FileInfo, 0, size) // Empty with room to grow.
|
|
|
|
d := &file.dirinfo.data
|
|
|
|
for n != 0 && !file.dirinfo.isempty {
|
|
|
|
if file.dirinfo.needdata {
|
|
|
|
e := syscall.FindNextFile(file.fd, d)
|
|
|
|
if e != nil {
|
|
|
|
if e == syscall.ERROR_NO_MORE_FILES {
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
err = &PathError{"FindNextFile", file.name, e}
|
|
|
|
if !wantAll {
|
|
|
|
fi = nil
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.dirinfo.needdata = true
|
|
|
|
name := syscall.UTF16ToString(d.FileName[0:])
|
|
|
|
if name == "." || name == ".." { // Useless names
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
f := &fileStat{
|
|
|
|
name: name,
|
|
|
|
sys: syscall.Win32FileAttributeData{
|
|
|
|
FileAttributes: d.FileAttributes,
|
|
|
|
CreationTime: d.CreationTime,
|
|
|
|
LastAccessTime: d.LastAccessTime,
|
|
|
|
LastWriteTime: d.LastWriteTime,
|
|
|
|
FileSizeHigh: d.FileSizeHigh,
|
|
|
|
FileSizeLow: d.FileSizeLow,
|
|
|
|
},
|
|
|
|
path: file.dirinfo.path + `\` + name,
|
|
|
|
}
|
|
|
|
n--
|
|
|
|
fi = append(fi, f)
|
|
|
|
}
|
|
|
|
if !wantAll && len(fi) == 0 {
|
|
|
|
return fi, io.EOF
|
|
|
|
}
|
|
|
|
return fi, nil
|
|
|
|
}
|
|
|
|
|
2012-01-16 22:51:54 -07:00
|
|
|
func (file *File) readdirnames(n int) (names []string, err error) {
|
2011-05-16 10:26:16 -06:00
|
|
|
fis, err := file.Readdir(n)
|
2010-04-13 17:30:11 -06:00
|
|
|
names = make([]string, len(fis))
|
|
|
|
for i, fi := range fis {
|
2011-11-30 10:04:16 -07:00
|
|
|
names[i] = fi.Name()
|
2010-04-13 17:30:11 -06:00
|
|
|
}
|
2011-05-16 10:26:16 -06:00
|
|
|
return names, err
|
2010-04-02 02:11:17 -06:00
|
|
|
}
|