os, internal/syscall/unix: consolidate Pipe implementations

All platforms with the pipe2 syscall now provide syscall.Pipe2.  Use it
to implement os.Pipe.

This also allows to drop the illumos-specific wrapper in
internal/sys/unix.

Change-Id: Ieb712a1498e86a389bad261e4e97c61c11d4bdd0
Reviewed-on: https://go-review.googlesource.com/c/go/+/390715
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Tobias Klauser 2022-03-08 14:54:53 +01:00 committed by Tobias Klauser
parent de8ddd97ac
commit 085ef537c4
5 changed files with 3 additions and 82 deletions

View File

@ -1,34 +0,0 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build illumos
package unix
import (
"syscall"
"unsafe"
)
//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so"
//go:linkname procpipe2 libc_pipe2
var procpipe2 uintptr
type _C_int int32
func Pipe2(p []int, flags int) error {
if len(p) != 2 {
return syscall.EINVAL
}
var pp [2]_C_int
_, _, errno := syscall6(uintptr(unsafe.Pointer(&procpipe2)), 2, uintptr(unsafe.Pointer(&pp)), uintptr(flags), 0, 0, 0, 0)
if errno != 0 {
return errno
}
p[0] = int(pp[0])
p[1] = int(pp[1])
return nil
}

View File

@ -1,25 +0,0 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build illumos
package os
import (
"internal/syscall/unix"
"syscall"
)
// Pipe returns a connected pair of Files; reads from r return bytes written to w.
// It returns the files and an error, if any.
func Pipe() (r *File, w *File, err error) {
var p [2]int
e := unix.Pipe2(p[0:], syscall.O_CLOEXEC)
if e != nil {
return nil, nil, NewSyscallError("pipe", e)
}
return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build dragonfly || freebsd || netbsd || openbsd
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
package os
@ -15,7 +15,7 @@ func Pipe() (r *File, w *File, err error) {
e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC)
if e != nil {
return nil, nil, NewSyscallError("pipe", e)
return nil, nil, NewSyscallError("pipe2", e)
}
return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil

View File

@ -1,20 +0,0 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package os
import "syscall"
// Pipe returns a connected pair of Files; reads from r return bytes written to w.
// It returns the files and an error, if any.
func Pipe() (r *File, w *File, err error) {
var p [2]int
e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC)
if e != nil {
return nil, nil, NewSyscallError("pipe2", e)
}
return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build aix || darwin || (js && wasm) || (solaris && !illumos)
//go:build aix || darwin || (js && wasm)
package os