Source file
src/os/readfrom_linux.go
1
2
3
4
5 package os
6
7 import (
8 "internal/poll"
9 "io"
10 )
11
12 var pollCopyFileRange = poll.CopyFileRange
13
14 func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
15
16
17 if f.appendMode {
18 return 0, false, nil
19 }
20
21 remain := int64(1 << 62)
22
23 lr, ok := r.(*io.LimitedReader)
24 if ok {
25 remain, r = lr.N, lr.R
26 if remain <= 0 {
27 return 0, true, nil
28 }
29 }
30
31 src, ok := r.(*File)
32 if !ok {
33 return 0, false, nil
34 }
35 if src.checkValid("ReadFrom") != nil {
36
37
38 return 0, false, nil
39 }
40
41 written, handled, err = pollCopyFileRange(&f.pfd, &src.pfd, remain)
42 if lr != nil {
43 lr.N -= written
44 }
45 return written, handled, NewSyscallError("copy_file_range", err)
46 }
47
View as plain text