Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(995)

Delta Between Two Patch Sets: src/pkg/os/dir_unix.go

Issue 5298073: code review 5298073: os: use error, io.EOF (Closed)
Left Patch Set: Created 13 years, 4 months ago
Right Patch Set: diff -r f751618f828b https://go.googlecode.com/hg/ Created 13 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/os/dir_plan9.go ('k') | src/pkg/os/dir_windows.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // +build darwin freebsd linux openbsd 5 // +build darwin freebsd linux openbsd
6 6
7 package os 7 package os
8 8
9 import ( 9 import (
10 "io"
10 "syscall" 11 "syscall"
11 ) 12 )
12 13
13 const ( 14 const (
14 blockSize = 4096 15 blockSize = 4096
15 ) 16 )
16 17
17 // Readdirnames reads and returns a slice of names from the directory f. 18 // Readdirnames reads and returns a slice of names from the directory f.
18 // 19 //
19 // If n > 0, Readdirnames returns at most n names. In this case, if 20 // If n > 0, Readdirnames returns at most n names. In this case, if
20 // Readdirnames returns an empty slice, it will return a non-nil error 21 // Readdirnames returns an empty slice, it will return a non-nil error
21 // explaining why. At the end of a directory, the error is os.EOF. 22 // explaining why. At the end of a directory, the error is os.EOF.
22 // 23 //
23 // If n <= 0, Readdirnames returns all the names from the directory in 24 // If n <= 0, Readdirnames returns all the names from the directory in
24 // a single slice. In this case, if Readdirnames succeeds (reads all 25 // a single slice. In this case, if Readdirnames succeeds (reads all
25 // the way to the end of the directory), it returns the slice and a 26 // the way to the end of the directory), it returns the slice and a
26 // nil os.Error. If it encounters an error before the end of the 27 // nil os.Error. If it encounters an error before the end of the
27 // directory, Readdirnames returns the names read until that point and 28 // directory, Readdirnames returns the names read until that point and
28 // a non-nil error. 29 // a non-nil error.
29 func (f *File) Readdirnames(n int) (names []string, err Error) { 30 func (f *File) Readdirnames(n int) (names []string, err error) {
30 // If this file has no dirinfo, create one. 31 // If this file has no dirinfo, create one.
31 if f.dirinfo == nil { 32 if f.dirinfo == nil {
32 f.dirinfo = new(dirInfo) 33 f.dirinfo = new(dirInfo)
33 // The buffer must be at least a block long. 34 // The buffer must be at least a block long.
34 f.dirinfo.buf = make([]byte, blockSize) 35 f.dirinfo.buf = make([]byte, blockSize)
35 } 36 }
36 d := f.dirinfo 37 d := f.dirinfo
37 38
38 size := n 39 size := n
39 if size <= 0 { 40 if size <= 0 {
(...skipping 16 matching lines...) Expand all
56 } 57 }
57 } 58 }
58 59
59 // Drain the buffer 60 // Drain the buffer
60 var nb, nc int 61 var nb, nc int
61 nb, nc, names = syscall.ParseDirent(d.buf[d.bufp:d.nbuf], n, nam es) 62 nb, nc, names = syscall.ParseDirent(d.buf[d.bufp:d.nbuf], n, nam es)
62 d.bufp += nb 63 d.bufp += nb
63 n -= nc 64 n -= nc
64 } 65 }
65 if n >= 0 && len(names) == 0 { 66 if n >= 0 && len(names) == 0 {
66 » » return names, EOF 67 » » return names, io.EOF
67 } 68 }
68 return names, nil 69 return names, nil
69 } 70 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b