From a7f19e9c2041d17119bde681964de7f560cf41c0 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 16 Dec 2024 13:14:32 +0100 Subject: [PATCH] unix: add Dup3 on dragonfly Use the same implementation as on freebsd which is also what the dragonfly libc uses. Change-Id: I0ed513ae15fcb6dac77b2fc76f662723d66b75c6 Reviewed-on: https://go-review.googlesource.com/c/sys/+/636435 Auto-Submit: Tobias Klauser Reviewed-by: Ian Lance Taylor Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot --- unix/dup3_test.go | 4 ++-- unix/syscall_dragonfly.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/unix/dup3_test.go b/unix/dup3_test.go index 9201e355..12baf126 100644 --- a/unix/dup3_test.go +++ b/unix/dup3_test.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 freebsd || linux || netbsd || openbsd +//go:build dragonfly || freebsd || linux || netbsd || openbsd package unix_test @@ -16,7 +16,7 @@ import ( ) func TestDup3(t *testing.T) { - tempFile, err := os.Create(filepath.Join(t.TempDir(), "TestDup")) + tempFile, err := os.Create(filepath.Join(t.TempDir(), "TestDup3")) if err != nil { t.Fatal(err) } diff --git a/unix/syscall_dragonfly.go b/unix/syscall_dragonfly.go index 97cb916f..be8c0020 100644 --- a/unix/syscall_dragonfly.go +++ b/unix/syscall_dragonfly.go @@ -246,6 +246,18 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e return sendfile(outfd, infd, offset, count) } +func Dup3(oldfd, newfd, flags int) error { + if oldfd == newfd || flags&^O_CLOEXEC != 0 { + return EINVAL + } + how := F_DUP2FD + if flags&O_CLOEXEC != 0 { + how = F_DUP2FD_CLOEXEC + } + _, err := fcntl(oldfd, how, newfd) + return err +} + /* * Exposed directly */