Debian Codegraph @

osfs/os_posix.go

raw symbols SCIP
1 //go:build !plan9 && !windows && !wasm
2
3 package osfs
4
5 import (
6 "syscall"
7
8 "golang.org/x/sys/unix"
9 )
10
11 func (f *file) Lock() error {
12 f.m.Lock()
13 defer f.m.Unlock()
14
15 return unix.Flock(int(f.File.Fd()), unix.LOCK_EX)
16 }
17
18 func (f *file) Unlock() error {
19 f.m.Lock()
20 defer f.m.Unlock()
21
22 return unix.Flock(int(f.File.Fd()), unix.LOCK_UN)
23 }
24
25 func (f *file) Sync() error {
26 return f.File.Sync()
27 }
28
29 // umask sets umask to a new value, and returns a func which allows the
30 // caller to reset it back to what it was originally.
31 func umask(m int) func() {
32 old := syscall.Umask(m)
33 return func() {
34 syscall.Umask(old)
35 }
36 }
37
38 // Fd exposes the underlying [os.File.Fd] func, which returns the
39 // system file descriptor or handle referencing the open file.
40 func (f *file) Fd() (uintptr, bool) {
41 return f.File.Fd(), true
42 }