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