From: Tobias Klauser Date: Tue, 8 Mar 2022 13:54:53 +0000 (+0100) Subject: os, internal/syscall/unix: consolidate Pipe implementations X-Git-Tag: go1.19beta1~1124 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=085ef537c4a2c57d373e72f4a110d9fae9a287be;p=gostls13.git 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 Run-TryBot: Tobias Klauser Trust: Matt Layher TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- diff --git a/src/internal/syscall/unix/pipe2_illumos.go b/src/internal/syscall/unix/pipe2_illumos.go deleted file mode 100644 index c6280f85e5..0000000000 --- a/src/internal/syscall/unix/pipe2_illumos.go +++ /dev/null @@ -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 -} diff --git a/src/os/pipe2_illumos.go b/src/os/pipe2_illumos.go deleted file mode 100644 index 354b35cc46..0000000000 --- a/src/os/pipe2_illumos.go +++ /dev/null @@ -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 -} diff --git a/src/os/pipe2_bsd.go b/src/os/pipe2_unix.go similarity index 81% rename from src/os/pipe2_bsd.go rename to src/os/pipe2_unix.go index 7eb1350d02..1e2e8ccb67 100644 --- a/src/os/pipe2_bsd.go +++ b/src/os/pipe2_unix.go @@ -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 diff --git a/src/os/pipe_linux.go b/src/os/pipe_linux.go deleted file mode 100644 index 52f4e21e7c..0000000000 --- a/src/os/pipe_linux.go +++ /dev/null @@ -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 -} diff --git a/src/os/pipe_bsd.go b/src/os/pipe_unix.go similarity index 91% rename from src/os/pipe_bsd.go rename to src/os/pipe_unix.go index 554d62111a..710f77670e 100644 --- a/src/os/pipe_bsd.go +++ b/src/os/pipe_unix.go @@ -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