Skip to content

Commit

Permalink
Fixed build on OpenBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
catap committed Nov 1, 2024
1 parent 397af53 commit f4d5b37
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
38 changes: 38 additions & 0 deletions copy/copy_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:build openbsd
// +build openbsd

package fs

import (
"io"
"os"

"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

func copyFile(source, target string) error {
src, err := os.Open(source)
if err != nil {
return errors.Wrapf(err, "failed to open source %s", source)
}
defer src.Close()
tgt, err := os.Create(target)
if err != nil {
return errors.Wrapf(err, "failed to open target %s", target)
}
defer tgt.Close()

return copyFileContent(tgt, src)
}

func copyFileContent(dst, src *os.File) error {
buf := bufferPool.Get().(*[]byte)
_, err := io.CopyBuffer(dst, src, *buf)
bufferPool.Put(buf)
return err
}

func mknod(dst string, mode uint32, rDev int) error {
return unix.Mknod(dst, uint32(mode), rDev)
}
4 changes: 2 additions & 2 deletions copy/copy_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build solaris || darwin || freebsd
// +build solaris darwin freebsd
//go:build solaris || darwin || freebsd || openbsd
// +build solaris darwin freebsd openbsd

package fs

Expand Down
2 changes: 1 addition & 1 deletion copy/stat_bsd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin freebsd netbsd openbsd
// +build darwin freebsd netbsd

package fs

Expand Down
17 changes: 17 additions & 0 deletions copy/stat_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build openbsd

package fs

import (
"syscall"
)

// Returns the last-accessed time
func StatAtime(st *syscall.Stat_t) syscall.Timespec {
return st.Atim
}

// Returns the last-modified time
func StatMtime(st *syscall.Stat_t) syscall.Timespec {
return st.Mtim
}

0 comments on commit f4d5b37

Please sign in to comment.