From e6e5e023fcebcbe305760bc8018d2364edda7acf Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 2 Sep 2015 10:54:21 +1000 Subject: [PATCH] x/sys/unix: expose fchmodat(2) and related constants on darwin/amd64 These are already exposed on Linux. I believe they were left out of darwin because fchmodat didn't exist on older versions of XNU. Change-Id: I166f2b23270937c1b6cc3bd73e7f7b72d2d488e9 Reviewed-on: https://go-review.googlesource.com/14092 Reviewed-by: Brad Fitzpatrick --- unix/syscall_darwin_amd64.go | 2 ++ unix/types_darwin.go | 7 +++++++ unix/zsyscall_darwin_amd64.go | 16 ++++++++++++++++ unix/ztypes_darwin_amd64.go | 5 +++++ 4 files changed, 30 insertions(+) diff --git a/unix/syscall_darwin_amd64.go b/unix/syscall_darwin_amd64.go index db5a02dc..7adb98de 100644 --- a/unix/syscall_darwin_amd64.go +++ b/unix/syscall_darwin_amd64.go @@ -11,6 +11,8 @@ import ( "unsafe" ) +//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) + func Getpagesize() int { return 4096 } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } diff --git a/unix/types_darwin.go b/unix/types_darwin.go index 2bb15cb8..11532618 100644 --- a/unix/types_darwin.go +++ b/unix/types_darwin.go @@ -241,3 +241,10 @@ type BpfHdr C.struct_bpf_hdr // Terminal handling type Termios C.struct_termios + +// fchmodat-like syscalls. + +const ( + AT_FDCWD = C.AT_FDCWD + AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW +) diff --git a/unix/zsyscall_darwin_amd64.go b/unix/zsyscall_darwin_amd64.go index e28b044e..74606b2f 100644 --- a/unix/zsyscall_darwin_amd64.go +++ b/unix/zsyscall_darwin_amd64.go @@ -1415,6 +1415,22 @@ func writelen(fd int, buf *byte, nbuf int) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) + use(unsafe.Pointer(_p0)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func gettimeofday(tp *Timeval) (sec int64, usec int32, err error) { r0, r1, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0) sec = int64(r0) diff --git a/unix/ztypes_darwin_amd64.go b/unix/ztypes_darwin_amd64.go index 6bedd16f..04465787 100644 --- a/unix/ztypes_darwin_amd64.go +++ b/unix/ztypes_darwin_amd64.go @@ -455,3 +455,8 @@ type Termios struct { Ispeed uint64 Ospeed uint64 } + +const ( + AT_FDCWD = -0x2 + AT_SYMLINK_NOFOLLOW = 0x20 +)