github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/os_bsd.go (about) 1 //go:build (freebsd || openbsd || netbsd || dragonfly || illumos || sqlite3_flock) && !sqlite3_nosys 2 3 package vfs 4 5 import ( 6 "os" 7 "time" 8 9 "golang.org/x/sys/unix" 10 ) 11 12 func osUnlock(file *os.File, start, len int64) _ErrorCode { 13 if start == 0 && len == 0 { 14 err := unix.Flock(int(file.Fd()), unix.LOCK_UN) 15 if err != nil { 16 return _IOERR_UNLOCK 17 } 18 } 19 return _OK 20 } 21 22 func osLock(file *os.File, how int, def _ErrorCode) _ErrorCode { 23 err := unix.Flock(int(file.Fd()), how) 24 return osLockErrorCode(err, def) 25 } 26 27 func osReadLock(file *os.File, _ /*start*/, _ /*len*/ int64, _ /*timeout*/ time.Duration) _ErrorCode { 28 return osLock(file, unix.LOCK_SH|unix.LOCK_NB, _IOERR_RDLOCK) 29 } 30 31 func osWriteLock(file *os.File, _ /*start*/, _ /*len*/ int64, _ /*timeout*/ time.Duration) _ErrorCode { 32 return osLock(file, unix.LOCK_EX|unix.LOCK_NB, _IOERR_LOCK) 33 }