pipe_glibc.go 1.0 KB

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