summaryrefslogtreecommitdiffstats
path: root/libgo/go/io/io.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/io/io.go')
-rw-r--r--libgo/go/io/io.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/libgo/go/io/io.go b/libgo/go/io/io.go
index 2b2f4d56714..1a6eca95a0d 100644
--- a/libgo/go/io/io.go
+++ b/libgo/go/io/io.go
@@ -203,10 +203,15 @@ func ReadFull(r Reader, buf []byte) (n int, err os.Error) {
// If dst implements the ReaderFrom interface,
// the copy is implemented by calling dst.ReadFrom(src).
func Copyn(dst Writer, src Reader, n int64) (written int64, err os.Error) {
- // If the writer has a ReadFrom method, use it to to do the copy.
+ // If the writer has a ReadFrom method, use it to do the copy.
// Avoids a buffer allocation and a copy.
if rt, ok := dst.(ReaderFrom); ok {
- return rt.ReadFrom(LimitReader(src, n))
+ written, err = rt.ReadFrom(LimitReader(src, n))
+ if written < n && err == nil {
+ // rt stopped early; must have been EOF.
+ err = os.EOF
+ }
+ return
}
buf := make([]byte, 32*1024)
for written < n {
@@ -246,12 +251,12 @@ func Copyn(dst Writer, src Reader, n int64) (written int64, err os.Error) {
// Otherwise, if src implements the WriterTo interface,
// the copy is implemented by calling src.WriteTo(dst).
func Copy(dst Writer, src Reader) (written int64, err os.Error) {
- // If the writer has a ReadFrom method, use it to to do the copy.
+ // If the writer has a ReadFrom method, use it to do the copy.
// Avoids an allocation and a copy.
if rt, ok := dst.(ReaderFrom); ok {
return rt.ReadFrom(src)
}
- // Similarly, if the reader has a WriteTo method, use it to to do the copy.
+ // Similarly, if the reader has a WriteTo method, use it to do the copy.
if wt, ok := src.(WriterTo); ok {
return wt.WriteTo(dst)
}
OpenPOWER on IntegriCloud