github.com/guyezi/gofrontend@v0.0.0-20200228202240-7a62a49e62c0/libgo/go/os/pipe_glibc.go (about)

     1  // Copyright 2013 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.
     4  
     5  // +build hurd linux
     6  
     7  package os
     8  
     9  import "syscall"
    10  
    11  // Pipe returns a connected pair of Files; reads from r return bytes written to w.
    12  // It returns the files and an error, if any.
    13  func Pipe() (r *File, w *File, err error) {
    14  	var p [2]int
    15  
    16  	e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC)
    17  	// pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it
    18  	// might not be implemented.
    19  	if e == syscall.ENOSYS {
    20  		// See ../syscall/exec.go for description of lock.
    21  		syscall.ForkLock.RLock()
    22  		e = syscall.Pipe(p[0:])
    23  		if e != nil {
    24  			syscall.ForkLock.RUnlock()
    25  			return nil, nil, NewSyscallError("pipe", e)
    26  		}
    27  		syscall.CloseOnExec(p[0])
    28  		syscall.CloseOnExec(p[1])
    29  		syscall.ForkLock.RUnlock()
    30  	} else if e != nil {
    31  		return nil, nil, NewSyscallError("pipe2", e)
    32  	}
    33  
    34  	return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil
    35  }