podman
1// Copyright 2014 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build dragonfly || freebsd || linux || netbsd
6
7package unix8
9import "unsafe"10
11// fcntl64Syscall is usually SYS_FCNTL, but is overridden on 32-bit Linux
12// systems by fcntl_linux_32bit.go to be SYS_FCNTL64.
13var fcntl64Syscall uintptr = SYS_FCNTL14
15func fcntl(fd int, cmd, arg int) (int, error) {16valptr, _, errno := Syscall(fcntl64Syscall, uintptr(fd), uintptr(cmd), uintptr(arg))17var err error18if errno != 0 {19err = errno20}21return int(valptr), err22}
23
24// FcntlInt performs a fcntl syscall on fd with the provided command and argument.
25func FcntlInt(fd uintptr, cmd, arg int) (int, error) {26return fcntl(int(fd), cmd, arg)27}
28
29// FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
30func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {31_, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk)))32if errno == 0 {33return nil34}35return errno36}
37