summaryrefslogtreecommitdiff
path: root/src/pkg/os/file_windows.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-06-30 15:34:22 +0200
committerOndřej Surý <ondrej@sury.org>2011-06-30 15:34:22 +0200
commitd39f5aa373a4422f7a5f3ee764fb0f6b0b719d61 (patch)
tree1833f8b72a4b3a8f00d0d143b079a8fcad01c6ae /src/pkg/os/file_windows.go
parent8652e6c371b8905498d3d314491d36c58d5f68d5 (diff)
downloadgolang-d39f5aa373a4422f7a5f3ee764fb0f6b0b719d61.tar.gz
Imported Upstream version 58upstream/58
Diffstat (limited to 'src/pkg/os/file_windows.go')
-rw-r--r--src/pkg/os/file_windows.go38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/pkg/os/file_windows.go b/src/pkg/os/file_windows.go
index 95f60b735..80886f6f5 100644
--- a/src/pkg/os/file_windows.go
+++ b/src/pkg/os/file_windows.go
@@ -123,12 +123,21 @@ func (file *File) Stat() (fi *FileInfo, err Error) {
}
// Readdir reads the contents of the directory associated with file and
-// returns an array of up to count FileInfo structures, as would be returned
-// by Lstat, in directory order. Subsequent calls on the same file will yield
+// returns an array of up to n FileInfo structures, as would be returned
+// by Lstat, in directory order. Subsequent calls on the same file will yield
// further FileInfos.
-// A negative count means to read until EOF.
-// Readdir returns the array and an Error, if any.
-func (file *File) Readdir(count int) (fi []FileInfo, err Error) {
+//
+// If n > 0, Readdir returns at most n FileInfo structures. In this case, if
+// Readdir returns an empty slice, it will return a non-nil error
+// explaining why. At the end of a directory, the error is os.EOF.
+//
+// If n <= 0, Readdir returns all the FileInfo from the directory in
+// a single slice. In this case, if Readdir succeeds (reads all
+// the way to the end of the directory), it returns the slice and a
+// nil os.Error. If it encounters an error before the end of the
+// directory, Readdir returns the FileInfo read until that point
+// and a non-nil error.
+func (file *File) Readdir(n int) (fi []FileInfo, err Error) {
if file == nil || file.fd < 0 {
return nil, EINVAL
}
@@ -136,12 +145,14 @@ func (file *File) Readdir(count int) (fi []FileInfo, err Error) {
return nil, &PathError{"Readdir", file.name, ENOTDIR}
}
di := file.dirinfo
- size := count
- if size < 0 {
+ wantAll := n <= 0
+ size := n
+ if wantAll {
+ n = -1
size = 100
}
fi = make([]FileInfo, 0, size) // Empty with room to grow.
- for count != 0 {
+ for n != 0 {
if di.usefirststat {
di.usefirststat = false
} else {
@@ -150,7 +161,11 @@ func (file *File) Readdir(count int) (fi []FileInfo, err Error) {
if e == syscall.ERROR_NO_MORE_FILES {
break
} else {
- return nil, &PathError{"FindNextFile", file.name, Errno(e)}
+ err = &PathError{"FindNextFile", file.name, Errno(e)}
+ if !wantAll {
+ fi = nil
+ }
+ return
}
}
}
@@ -159,9 +174,12 @@ func (file *File) Readdir(count int) (fi []FileInfo, err Error) {
if f.Name == "." || f.Name == ".." { // Useless names
continue
}
- count--
+ n--
fi = append(fi, f)
}
+ if !wantAll && len(fi) == 0 {
+ return fi, EOF
+ }
return fi, nil
}