summaryrefslogtreecommitdiff
path: root/src/pkg/io/bytebuffer.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-06-23 15:20:40 -0700
committerRob Pike <r@golang.org>2009-06-23 15:20:40 -0700
commit9998ffdb78e6706805c52c2c39428cff6f31506d (patch)
treea2a21597bc7d536e9329e8e299e9c6caf7aac5e2 /src/pkg/io/bytebuffer.go
parentfe0316493f9eb341d51692fe6e283bffd17279e3 (diff)
downloadgolang-9998ffdb78e6706805c52c2c39428cff6f31506d.tar.gz
fix io.Bytebuffer.Read for new EOF semantics
R=rsc DELTA=7 (5 added, 0 deleted, 2 changed) OCL=30657 CL=30659
Diffstat (limited to 'src/pkg/io/bytebuffer.go')
-rw-r--r--src/pkg/io/bytebuffer.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/pkg/io/bytebuffer.go b/src/pkg/io/bytebuffer.go
index 11c8a1a87..2c356192e 100644
--- a/src/pkg/io/bytebuffer.go
+++ b/src/pkg/io/bytebuffer.go
@@ -87,8 +87,13 @@ func (b *ByteBuffer) WriteByte(c byte) os.Error {
}
// Read reads the next len(p) bytes from the buffer or until the buffer
-// is drained. The return value n is the number of bytes read; err is always nil.
+// is drained. The return value n is the number of bytes read. If the
+// buffer has no data to return, err is os.EOF even if len(p) is zero;
+// otherwise it is nil.
func (b *ByteBuffer) Read(p []byte) (n int, err os.Error) {
+ if b.off >= len(b.buf) {
+ return 0, os.EOF
+ }
m := b.Len();
n = len(p);
@@ -99,7 +104,7 @@ func (b *ByteBuffer) Read(p []byte) (n int, err os.Error) {
bytecopy(p, 0, b.buf, b.off, n);
b.off += n;
- return n, nil
+ return n, err
}
// ReadByte reads and returns the next byte from the buffer.