diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-01-30 15:38:19 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-01-30 15:38:19 +0100 |
commit | 4cecda6c347bd6902b960c6a35a967add7070b0d (patch) | |
tree | a462e224ff41ec9f3eb1a0b6e815806f9e8804ad /src/pkg/os/dir_plan9.go | |
parent | 6c7ca6e4d4e26e4c8cbe0d183966011b3b088a0a (diff) | |
download | golang-4cecda6c347bd6902b960c6a35a967add7070b0d.tar.gz |
Imported Upstream version 2012.01.27upstream-weekly/2012.01.27
Diffstat (limited to 'src/pkg/os/dir_plan9.go')
-rw-r--r-- | src/pkg/os/dir_plan9.go | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/src/pkg/os/dir_plan9.go b/src/pkg/os/dir_plan9.go index bbc2cb647..f2dc15409 100644 --- a/src/pkg/os/dir_plan9.go +++ b/src/pkg/os/dir_plan9.go @@ -5,25 +5,12 @@ package os import ( + "errors" + "io" "syscall" ) -// Readdir reads the contents of the directory associated with file and -// 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. -// -// If n > 0, Readdir returns at most n FileInfo structures. In this case, if -// Readdirnames 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) { +func (file *File) readdir(n int) (fi []FileInfo, err error) { // If this file has no dirinfo, create one. if file.dirinfo == nil { file.dirinfo = new(dirInfo) @@ -39,12 +26,12 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) { // Refill the buffer if necessary if d.bufp >= d.nbuf { d.bufp = 0 - var e Error + var e error d.nbuf, e = file.Read(d.buf[:]) - if e != nil && e != EOF { + if e != nil && e != io.EOF { return result, &PathError{"readdir", file.name, e} } - if e == EOF { + if e == io.EOF { break } if d.nbuf < syscall.STATFIXLEN { @@ -62,37 +49,23 @@ func (file *File) Readdir(n int) (fi []FileInfo, err Error) { if e != nil { return result, &PathError{"readdir", file.name, e} } - var f FileInfo - fileInfoFromStat(&f, dir) - result = append(result, f) + result = append(result, fileInfoFromStat(dir)) d.bufp += int(m) n-- } if n >= 0 && len(result) == 0 { - return result, EOF + return result, io.EOF } return result, nil } -// Readdirnames reads and returns a slice of names from the directory f. -// -// If n > 0, Readdirnames returns at most n names. In this case, if -// Readdirnames 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, Readdirnames returns all the names from the directory in -// a single slice. In this case, if Readdirnames 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, Readdirnames returns the names read until that point and -// a non-nil error. -func (file *File) Readdirnames(n int) (names []string, err Error) { +func (file *File) readdirnames(n int) (names []string, err error) { fi, err := file.Readdir(n) names = make([]string, len(fi)) for i := range fi { - names[i] = fi[i].Name + names[i] = fi[i].Name() } return } @@ -160,7 +133,7 @@ func pdir(b []byte, d *Dir) []byte { // UnmarshalDir reads a 9P Stat message from a 9P protocol message stored in b, // returning the corresponding Dir struct. -func UnmarshalDir(b []byte) (d *Dir, err Error) { +func UnmarshalDir(b []byte) (d *Dir, err error) { n := uint16(0) n, b = gbit16(b) @@ -292,9 +265,9 @@ func pbit64(b []byte, x uint64) []byte { // pstring appends a Go string s to a 9P message b. func pstring(b []byte, s string) []byte { if len(s) >= 1<<16 { - panic(NewError("string too long")) + panic(errors.New("string too long")) } b = pbit16(b, uint16(len(s))) - b = append(b, []byte(s)...) + b = append(b, s...) return b } |