]> Cypherpunks repositories - gostls13.git/commitdiff
os, internal/syscall/unix: consolidate Pipe implementations
authorTobias Klauser <tklauser@distanz.ch>
Tue, 8 Mar 2022 13:54:53 +0000 (14:54 +0100)
committerTobias Klauser <tobias.klauser@gmail.com>
Tue, 8 Mar 2022 21:16:44 +0000 (21:16 +0000)
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>
src/internal/syscall/unix/pipe2_illumos.go [deleted file]
src/os/pipe2_illumos.go [deleted file]
src/os/pipe2_unix.go [moved from src/os/pipe2_bsd.go with 81% similarity]
src/os/pipe_linux.go [deleted file]
src/os/pipe_unix.go [moved from src/os/pipe_bsd.go with 91% similarity]

diff --git a/src/internal/syscall/unix/pipe2_illumos.go b/src/internal/syscall/unix/pipe2_illumos.go
deleted file mode 100644 (file)
index c6280f8..0000000
+++ /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 (file)
index 354b35c..0000000
+++ /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
-}
similarity index 81%
rename from src/os/pipe2_bsd.go
rename to src/os/pipe2_unix.go
index 7eb1350d025347dd37ce09810511ae3f8d0d5511..1e2e8ccb67cb78510589597ee1ed038575ed251d 100644 (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
diff --git a/src/os/pipe_linux.go b/src/os/pipe_linux.go
deleted file mode 100644 (file)
index 52f4e21..0000000
+++ /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
-}
similarity index 91%
rename from src/os/pipe_bsd.go
rename to src/os/pipe_unix.go
index 554d62111a570b6c65feae24ba3737ea68d1bb27..710f77670e27635095ee26f142143a7807f4097c 100644 (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