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.
9 // Pipe returns a connected pair of Files; reads from r return bytes written to w.
10 // It returns the files and an error, if any.
11 func Pipe() (r
*File
, w
*File
, err error
) {
14 e
:= syscall
.Pipe2(p
[0:], syscall
.O_CLOEXEC
)
15 // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it
16 // might not be implemented.
17 if e
== syscall
.ENOSYS
{
18 // See ../syscall/exec.go for description of lock.
19 syscall
.ForkLock
.RLock()
20 e
= syscall
.Pipe(p
[0:])
22 syscall
.ForkLock
.RUnlock()
23 return nil, nil, NewSyscallError("pipe", e
)
25 syscall
.CloseOnExec(p
[0])
26 syscall
.CloseOnExec(p
[1])
27 syscall
.ForkLock
.RUnlock()
29 return nil, nil, NewSyscallError("pipe2", e
)
32 return NewFile(uintptr(p
[0]), "|0"), NewFile(uintptr(p
[1]), "|1"), nil