mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
354e61cc52
commit
a1646fd50e
2 changed files with 18 additions and 12 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue