1
0
mirror of https://github.com/golang/go synced 2024-11-20 04:44:40 -07:00

syscall: add Utimes on Darwin/FreeBSD, add Futimes everywhere

Needed for CL 1103041 and beyond.

R=adg, bradfitzpatrick
CC=bradfitz, golang-dev
https://golang.org/cl/1172042
This commit is contained in:
Russ Cox 2010-05-19 17:47:57 -07:00
parent ce7487baa8
commit cbc01a3e76
7 changed files with 62 additions and 10 deletions

View File

@ -164,7 +164,13 @@ esac
(
if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >zerrors_$GOOSARCH.go"; fi
if [ -n "$mksyscall" ]; then echo "$mksyscall syscall_$GOOS.go syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go"; fi
syscall_goos="syscall_$GOOS.go"
case "$GOOS" in
darwin | freebsd)
syscall_goos="syscall_bsd.go $syscall_goos"
;;
esac
if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go"; fi
if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.c |gofmt >ztypes_$GOOSARCH.go"; fi
) | $run

View File

@ -451,9 +451,27 @@ func SysctlUint32(name string) (value uint32, errno int) {
return *(*uint32)(unsafe.Pointer(&buf[0])), 0
}
//sys utimes(path string, timeval *[2]Timeval) (errno int)
func Utimes(path string, tv []Timeval) (errno int) {
if len(tv) != 2 {
return EINVAL
}
return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
}
//sys futimes(fd int, timeval *[2]Timeval) (errno int)
func Futimes(fd int, tv []Timeval) (errno int) {
if len(tv) != 2 {
return EINVAL
}
return futimes(fd, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
}
//sys fcntl(fd int, cmd int, arg int) (val int, errno int)
// TODO: wrap
// Acct(name nil-string) (errno int)
// Futimes(fd int, timeval *Timeval) (errno int) // Pointer to 2 timevals!
// Gethostuuid(uuid *byte, timeout *Timespec) (errno int)
// Getsockopt(s int, level int, name int, val *byte, vallen *int) (errno int)
// Madvise(addr *byte, len int, behav int) (errno int)
@ -463,5 +481,3 @@ func SysctlUint32(name string) (value uint32, errno int) {
// Ptrace(req int, pid int, addr uintptr, data int) (ret uintptr, errno int)
// Recvmsg(s int, msg *Msghdr, flags int) (n int, errno int)
// Sendmsg(s int, msg *Msghdr, flags int) (n int, errno int)
// Utimes(path string, timeval *Timeval) (errno int) // Pointer to 2 timevals!
//sys fcntl(fd int, cmd int, arg int) (val int, errno int)

View File

@ -49,12 +49,18 @@ func Utimes(path string, tv []Timeval) (errno int) {
return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
}
//sys futimesat(dirfd int, path string, times *[2]Timeval) (errno int)
//sys futimesat(dirfd int, path *byte, times *[2]Timeval) (errno int)
func Futimesat(dirfd int, path string, tv []Timeval) (errno int) {
if len(tv) != 2 {
return EINVAL
}
return futimesat(dirfd, path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
return futimesat(dirfd, StringBytePtr(path), (*[2]Timeval)(unsafe.Pointer(&tv[0])))
}
func Futimes(fd int, tv []Timeval) (errno int) {
// Believe it or not, this is the best we can do on Linux
// (and is what glibc does).
return Utimes("/proc/self/fd/"+str(fd), tv)
}
const ImplementsGetwd = true

View File

@ -121,6 +121,18 @@ func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr)
return
}
func utimes(path string, timeval *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(unsafe.Pointer(timeval)), 0)
errno = int(e1)
return
}
func futimes(fd int, timeval *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0)
errno = int(e1)
return
}
func fcntl(fd int, cmd int, arg int) (val int, errno int) {
r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg))
val = int(r0)

View File

@ -121,6 +121,18 @@ func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr)
return
}
func utimes(path string, timeval *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(unsafe.Pointer(timeval)), 0)
errno = int(e1)
return
}
func futimes(fd int, timeval *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_FUTIMES, uintptr(fd), uintptr(unsafe.Pointer(timeval)), 0)
errno = int(e1)
return
}
func fcntl(fd int, cmd int, arg int) (val int, errno int) {
r0, _, e1 := Syscall(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg))
val = int(r0)

View File

@ -31,8 +31,8 @@ func utimes(path string, times *[2]Timeval) (errno int) {
return
}
func futimesat(dirfd int, path string, times *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_FUTIMESAT, uintptr(dirfd), uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(unsafe.Pointer(times)))
func futimesat(dirfd int, path *byte, times *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_FUTIMESAT, uintptr(dirfd), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(times)))
errno = int(e1)
return
}

View File

@ -31,8 +31,8 @@ func utimes(path string, times *[2]Timeval) (errno int) {
return
}
func futimesat(dirfd int, path string, times *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_FUTIMESAT, uintptr(dirfd), uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(unsafe.Pointer(times)))
func futimesat(dirfd int, path *byte, times *[2]Timeval) (errno int) {
_, _, e1 := Syscall(SYS_FUTIMESAT, uintptr(dirfd), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(times)))
errno = int(e1)
return
}