Black Lives Matter. Support the Equal Justice Initiative.

Source file src/os/pipe_bsd.go

Documentation: os

     1  // Copyright 2009 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  //go:build aix || darwin || (js && wasm) || (solaris && !illumos)
     6  // +build aix darwin js,wasm solaris,!illumos
     7  
     8  package os
     9  
    10  import "syscall"
    11  
    12  // Pipe returns a connected pair of Files; reads from r return bytes written to w.
    13  // It returns the files and an error, if any.
    14  func Pipe() (r *File, w *File, err error) {
    15  	var p [2]int
    16  
    17  	// See ../syscall/exec.go for description of lock.
    18  	syscall.ForkLock.RLock()
    19  	e := syscall.Pipe(p[0:])
    20  	if e != nil {
    21  		syscall.ForkLock.RUnlock()
    22  		return nil, nil, NewSyscallError("pipe", e)
    23  	}
    24  	syscall.CloseOnExec(p[0])
    25  	syscall.CloseOnExec(p[1])
    26  	syscall.ForkLock.RUnlock()
    27  
    28  	return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil
    29  }
    30  

View as plain text