diff --git a/unix/dup3_test.go b/unix/dup3_test.go index 9201e35580..12baf12625 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 97cb916f2c..be8c002070 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 */ diff --git a/windows/dll_windows.go b/windows/dll_windows.go index 4e613cf633..3ca814f54d 100644 --- a/windows/dll_windows.go +++ b/windows/dll_windows.go @@ -43,8 +43,8 @@ type DLL struct { // LoadDLL loads DLL file into memory. // // Warning: using LoadDLL without an absolute path name is subject to -// DLL preloading attacks. To safely load a system DLL, use LazyDLL -// with System set to true, or use LoadLibraryEx directly. +// DLL preloading attacks. To safely load a system DLL, use [NewLazySystemDLL], +// or use [LoadLibraryEx] directly. func LoadDLL(name string) (dll *DLL, err error) { namep, err := UTF16PtrFromString(name) if err != nil { @@ -271,6 +271,9 @@ func (d *LazyDLL) NewProc(name string) *LazyProc { } // NewLazyDLL creates new LazyDLL associated with DLL file. +// +// Warning: using NewLazyDLL without an absolute path name is subject to +// DLL preloading attacks. To safely load a system DLL, use [NewLazySystemDLL]. func NewLazyDLL(name string) *LazyDLL { return &LazyDLL{Name: name} } @@ -410,7 +413,3 @@ func loadLibraryEx(name string, system bool) (*DLL, error) { } return &DLL{Name: name, Handle: h}, nil } - -type errString string - -func (s errString) Error() string { return string(s) }