MATCH: Add patterns from phiopt's minmax_replacement
[official-gcc.git] / libgo / go / os / readfrom_linux.go
blob63ea45cf6516435265b2b71d81cca5a29ac5f971
1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package os
7 import (
8 "internal/poll"
9 "io"
12 var pollCopyFileRange = poll.CopyFileRange
14 func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
15 // copy_file_range(2) does not support destinations opened with
16 // O_APPEND, so don't even try.
17 if f.appendMode {
18 return 0, false, nil
21 remain := int64(1 << 62)
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
31 src, ok := r.(*File)
32 if !ok {
33 return 0, false, nil
35 if src.checkValid("ReadFrom") != nil {
36 // Avoid returning the error as we report handled as false,
37 // leave further error handling as the responsibility of the caller.
38 return 0, false, nil
41 written, handled, err = pollCopyFileRange(&f.pfd, &src.pfd, remain)
42 if lr != nil {
43 lr.N -= written
45 return written, handled, NewSyscallError("copy_file_range", err)