diff options
author | Russ Cox <rsc@golang.org> | 2009-06-22 13:26:13 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-06-22 13:26:13 -0700 |
commit | bcee995c1b91bb489b9555213ef4254602bf920b (patch) | |
tree | bee9639cb9ffde3688be8468c7b20d5069f69387 /src/pkg/os/file.go | |
parent | dd5f6ae3ff81db61370b4d13fd03ae46b0bc23da (diff) | |
download | golang-bcee995c1b91bb489b9555213ef4254602bf920b.tar.gz |
introduce os.EOF and io.ErrUnexpectedEOF.
remove io.ErrEOF.
rename io.FullRead to io.ReadFull, to match
ReadAtLeast and ReadAll.
remove io.FullReader, because it is now unused.
R=r
DELTA=295 (88 added, 105 deleted, 102 changed)
OCL=30544
CL=30588
Diffstat (limited to 'src/pkg/os/file.go')
-rw-r--r-- | src/pkg/os/file.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/pkg/os/file.go b/src/pkg/os/file.go index 1562b1b0e..5b6115932 100644 --- a/src/pkg/os/file.go +++ b/src/pkg/os/file.go @@ -97,9 +97,21 @@ func (file *File) Close() Error { return err; } +type eofError int +func (eofError) String() string { + return "EOF" +} + +// EOF is the Error returned by Read when no more input is available. +// Functions should return EOF only to signal a graceful end of input. +// If the EOF occurs unexpectedly in a structured data stream, +// the appropriate error is either io.ErrUnexpectedEOF or some other error +// giving more detail. +var EOF Error = eofError(0) + // Read reads up to len(b) bytes from the File. // It returns the number of bytes read and an Error, if any. -// EOF is signaled by a zero count with a nil Error. +// EOF is signaled by a zero count with err set to EOF. // TODO(r): Add Pread, Pwrite (maybe ReadAt, WriteAt). func (file *File) Read(b []byte) (ret int, err Error) { if file == nil { @@ -109,6 +121,9 @@ func (file *File) Read(b []byte) (ret int, err Error) { if n < 0 { n = 0; } + if n == 0 && e == 0 { + return 0, EOF + } return n, ErrnoToError(e); } |