Skip to content

Instantly share code, notes, and snippets.

@jedy
Created November 29, 2012 08:11
Show Gist options
  • Save jedy/4167513 to your computer and use it in GitHub Desktop.
Save jedy/4167513 to your computer and use it in GitHub Desktop.
file record lock in golang
package main
import (
"fmt"
"os"
"syscall"
"unsafe"
)
func main() {
k := struct {
Type uint32
Whence uint32
Start uint64
Len uint64
Pid uint32
}{
syscall.F_WRLCK,
uint32(os.SEEK_SET),
0,
10,
0,
}
f, err := os.OpenFile("x", os.O_RDWR, 0666)
_, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_SETLKW), uintptr(unsafe.Pointer(&k)))
fmt.Println(errno)
b := make([]byte, 1)
os.Stdin.Read(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment