make bytes.Copy both src- and dst- limited

and return the number of bytes copied.

R=r
DELTA=18  (6 added, 0 deleted, 12 changed)
OCL=30693
CL=30712
This commit is contained in:
Russ Cox 2009-06-24 15:35:35 -07:00
parent 354e61cc52
commit a1646fd50e
2 changed files with 18 additions and 12 deletions

View file

@ -41,10 +41,14 @@ func Equal(a, b []byte) bool {
return true
}
// Copy copies the source to the destination, stopping when the source
// is all transferred. The caller must guarantee that there is enough
// room in the destination. It returns the number of bytes copied
// Copy copies bytes from src to dst,
// stopping when either all of src has been copied
// or all of dst has been filled.
// It returns the number of bytes copied.
func Copy(dst, src []byte) int {
if len(src) > len(dst) {
src = src[0:len(dst)];
}
for i, x := range src {
dst[i] = x
}