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"
|
2017-02-10 16:17:38 -07:00
|
|
|
"runtime"
|
2016-08-14 10:39:00 -06:00
|
|
|
"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}
|
|
|
|
}
|
|
|
|
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 {
|
2017-02-10 16:17:38 -07:00
|
|
|
e := file.pfd.FindNextFile(d)
|
|
|
|
runtime.KeepAlive(file)
|
2016-08-14 10:39:00 -06:00
|
|
|
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,
|
|
|
|
},
|
2017-05-07 20:49:04 -06:00
|
|
|
path: file.dirinfo.path,
|
|
|
|
appendNameToPath: true,
|
2016-08-14 10:39:00 -06:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|