Skip to content

Commit

Permalink
unix: add Dup3 on dragonfly
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Run-TryBot: Tobias Klauser <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
tklauser authored and gopherbot committed Dec 17, 2024
1 parent fe16172 commit a7f19e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions unix/dup3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions unix/syscall_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit a7f19e9

Please sign in to comment.