mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 23:27:31 -04:00
unix: add utimensat and use it for UtimesNano on BSD
Follow golang.org/cl/55130 and add the utimensat syscall on *BSD. Use it in UtimesNano and UtimesNanoAt (which is added on *BSD, akin to the already existing implementation on Linux and Solaris). Also add AT_FDCWD and AT_SYMLINK_NOFOLLOW where they are missing. These might be used with UtimesNanoAt. In order to be able to generate the syscalls, also add two missing $GOOS_$GOARCH patterns to mkall.sh. As a side effect, some additional syscalls are added for openbsd/arm. Change-Id: I85351098002209f8454ec328cef0cfe9d12c5214 Reviewed-on: https://go-review.googlesource.com/55071 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Ian Lance Taylor
parent
c84c1ab9fd
commit
2d3e384235
+18
-2
@@ -561,13 +561,19 @@ func Utimes(path string, tv []Timeval) error {
|
||||
|
||||
func UtimesNano(path string, ts []Timespec) error {
|
||||
if ts == nil {
|
||||
err := utimensat(AT_FDCWD, path, nil, 0)
|
||||
if err != ENOSYS {
|
||||
return err
|
||||
}
|
||||
return utimes(path, nil)
|
||||
}
|
||||
// TODO: The BSDs can do utimensat with SYS_UTIMENSAT but it
|
||||
// isn't supported by darwin so this uses utimes instead
|
||||
if len(ts) != 2 {
|
||||
return EINVAL
|
||||
}
|
||||
err := utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
|
||||
if err != ENOSYS {
|
||||
return err
|
||||
}
|
||||
// Not as efficient as it could be because Timespec and
|
||||
// Timeval have different types in the different OSes
|
||||
tv := [2]Timeval{
|
||||
@@ -577,6 +583,16 @@ func UtimesNano(path string, ts []Timespec) error {
|
||||
return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
|
||||
}
|
||||
|
||||
func UtimesNanoAt(dirfd int, path string, ts []Timespec, flags int) error {
|
||||
if ts == nil {
|
||||
return utimensat(dirfd, path, nil, flags)
|
||||
}
|
||||
if len(ts) != 2 {
|
||||
return EINVAL
|
||||
}
|
||||
return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), flags)
|
||||
}
|
||||
|
||||
//sys futimes(fd int, timeval *[2]Timeval) (err error)
|
||||
|
||||
func Futimes(fd int, tv []Timeval) error {
|
||||
|
||||
Reference in New Issue
Block a user