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

syscall: implement windows version of Fsync

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4158043
This commit is contained in:
Alex Brainman 2011-02-09 14:54:54 +11:00
parent e6f9b2f110
commit 5e83d40904
2 changed files with 24 additions and 3 deletions

View File

@ -158,6 +158,7 @@ func NewCallback(fn interface{}) uintptr
//sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, errno int) [failretval==nil] = shell32.CommandLineToArgvW //sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, errno int) [failretval==nil] = shell32.CommandLineToArgvW
//sys LocalFree(hmem uint32) (handle uint32, errno int) [failretval!=0] //sys LocalFree(hmem uint32) (handle uint32, errno int) [failretval!=0]
//sys SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, errno int) //sys SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, errno int)
//sys FlushFileBuffers(handle int32) (ok bool, errno int)
// syscall interface implementation for other packages // syscall interface implementation for other packages
@ -478,6 +479,13 @@ func Utimes(path string, tv []Timeval) (errno int) {
return 0 return 0
} }
func Fsync(fd int) (errno int) {
if ok, e := FlushFileBuffers(int32(fd)); !ok {
return e
}
return 0
}
// net api calls // net api calls
//sys WSAStartup(verreq uint32, data *WSAData) (sockerrno int) = wsock32.WSAStartup //sys WSAStartup(verreq uint32, data *WSAData) (sockerrno int) = wsock32.WSAStartup
@ -732,9 +740,6 @@ func Chown(path string, uid int, gid int) (errno int) { return EWINDOWS }
func Lchown(path string, uid int, gid int) (errno int) { return EWINDOWS } func Lchown(path string, uid int, gid int) (errno int) { return EWINDOWS }
func Fchown(fd int, uid int, gid int) (errno int) { return EWINDOWS } func Fchown(fd int, uid int, gid int) (errno int) { return EWINDOWS }
// TODO(brainman): use FlushFileBuffers Windows api to implement Fsync.
func Fsync(fd int) (errno int) { return EWINDOWS }
func Getuid() (uid int) { return -1 } func Getuid() (uid int) { return -1 }
func Geteuid() (euid int) { return -1 } func Geteuid() (euid int) { return -1 }
func Getgid() (gid int) { return -1 } func Getgid() (gid int) { return -1 }

View File

@ -67,6 +67,7 @@ var (
procCommandLineToArgvW = getSysProcAddr(modshell32, "CommandLineToArgvW") procCommandLineToArgvW = getSysProcAddr(modshell32, "CommandLineToArgvW")
procLocalFree = getSysProcAddr(modkernel32, "LocalFree") procLocalFree = getSysProcAddr(modkernel32, "LocalFree")
procSetHandleInformation = getSysProcAddr(modkernel32, "SetHandleInformation") procSetHandleInformation = getSysProcAddr(modkernel32, "SetHandleInformation")
procFlushFileBuffers = getSysProcAddr(modkernel32, "FlushFileBuffers")
procWSAStartup = getSysProcAddr(modwsock32, "WSAStartup") procWSAStartup = getSysProcAddr(modwsock32, "WSAStartup")
procWSACleanup = getSysProcAddr(modwsock32, "WSACleanup") procWSACleanup = getSysProcAddr(modwsock32, "WSACleanup")
procsocket = getSysProcAddr(modwsock32, "socket") procsocket = getSysProcAddr(modwsock32, "socket")
@ -883,6 +884,21 @@ func SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, err
return return
} }
func FlushFileBuffers(handle int32) (ok bool, errno int) {
r0, _, e1 := Syscall(procFlushFileBuffers, 1, uintptr(handle), 0, 0)
ok = bool(r0 != 0)
if !ok {
if e1 != 0 {
errno = int(e1)
} else {
errno = EINVAL
}
} else {
errno = 0
}
return
}
func WSAStartup(verreq uint32, data *WSAData) (sockerrno int) { func WSAStartup(verreq uint32, data *WSAData) (sockerrno int) {
r0, _, _ := Syscall(procWSAStartup, 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0) r0, _, _ := Syscall(procWSAStartup, 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
sockerrno = int(r0) sockerrno = int(r0)