-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsyscall_linux.go
66 lines (58 loc) · 1.32 KB
/
syscall_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package bluetooth
import (
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
func ioR(t, nr, size uint) uint {
return (2 << 30) | (t << 8) | nr | (size << 16)
}
func writev(fd int, iovs []unix.Iovec) (n int, err error) {
var _p0 unsafe.Pointer
n = 0
if len(iovs) > 0 {
_p0 = unsafe.Pointer(&iovs[0])
} else {
return
}
r0, _, e1 := unix.Syscall(unix.SYS_WRITEV, uintptr(fd), uintptr(_p0), uintptr(len(iovs)))
n = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
func setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) {
_, _, e1 := unix.Syscall6(unix.SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
func ioctl(fd int, req uint, arg unsafe.Pointer) (err error) {
_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg))
if e1 != 0 {
err = errnoErr(e1)
}
return
}
var (
errEAGAIN error = syscall.EAGAIN
errEINVAL error = syscall.EINVAL
errENOENT error = syscall.ENOENT
)
// errnoErr returns common boxed Errno values, to prevent
// allocations at runtime.
func errnoErr(e syscall.Errno) error {
switch e {
case 0:
return nil
case syscall.EAGAIN:
return errEAGAIN
case syscall.EINVAL:
return errEINVAL
case syscall.ENOENT:
return errENOENT
}
return e
}