Skip to content

Commit a7f19e9

Browse files
tklausergopherbot
authored andcommitted
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 <[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]>
1 parent fe16172 commit a7f19e9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: unix/dup3_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build freebsd || linux || netbsd || openbsd
5+
//go:build dragonfly || freebsd || linux || netbsd || openbsd
66

77
package unix_test
88

@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
func TestDup3(t *testing.T) {
19-
tempFile, err := os.Create(filepath.Join(t.TempDir(), "TestDup"))
19+
tempFile, err := os.Create(filepath.Join(t.TempDir(), "TestDup3"))
2020
if err != nil {
2121
t.Fatal(err)
2222
}

Diff for: unix/syscall_dragonfly.go

+12
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
246246
return sendfile(outfd, infd, offset, count)
247247
}
248248

249+
func Dup3(oldfd, newfd, flags int) error {
250+
if oldfd == newfd || flags&^O_CLOEXEC != 0 {
251+
return EINVAL
252+
}
253+
how := F_DUP2FD
254+
if flags&O_CLOEXEC != 0 {
255+
how = F_DUP2FD_CLOEXEC
256+
}
257+
_, err := fcntl(oldfd, how, newfd)
258+
return err
259+
}
260+
249261
/*
250262
* Exposed directly
251263
*/

0 commit comments

Comments
 (0)