Mercurial > yakumo_izuru > aya
comparison vendor/golang.org/x/sys/unix/syscall_illumos.go @ 68:4b79810863f6 draft
Ready to release 0.6.0
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author | yakumo.izuru |
---|---|
date | Wed, 13 Sep 2023 10:49:50 +0000 |
parents | 787b5ee0289d |
children |
comparison
equal
deleted
inserted
replaced
67:4edfa07d5fe0 | 68:4b79810863f6 |
---|---|
8 // +build amd64,illumos | 8 // +build amd64,illumos |
9 | 9 |
10 package unix | 10 package unix |
11 | 11 |
12 import ( | 12 import ( |
13 "fmt" | |
14 "runtime" | |
15 "unsafe" | 13 "unsafe" |
16 ) | 14 ) |
17 | 15 |
18 func bytes2iovec(bs [][]byte) []Iovec { | 16 func bytes2iovec(bs [][]byte) []Iovec { |
19 iovecs := make([]Iovec, len(bs)) | 17 iovecs := make([]Iovec, len(bs)) |
77 Close(nfd) | 75 Close(nfd) |
78 nfd = 0 | 76 nfd = 0 |
79 } | 77 } |
80 return | 78 return |
81 } | 79 } |
82 | |
83 //sys putmsg(fd int, clptr *strbuf, dataptr *strbuf, flags int) (err error) | |
84 | |
85 func Putmsg(fd int, cl []byte, data []byte, flags int) (err error) { | |
86 var clp, datap *strbuf | |
87 if len(cl) > 0 { | |
88 clp = &strbuf{ | |
89 Len: int32(len(cl)), | |
90 Buf: (*int8)(unsafe.Pointer(&cl[0])), | |
91 } | |
92 } | |
93 if len(data) > 0 { | |
94 datap = &strbuf{ | |
95 Len: int32(len(data)), | |
96 Buf: (*int8)(unsafe.Pointer(&data[0])), | |
97 } | |
98 } | |
99 return putmsg(fd, clp, datap, flags) | |
100 } | |
101 | |
102 //sys getmsg(fd int, clptr *strbuf, dataptr *strbuf, flags *int) (err error) | |
103 | |
104 func Getmsg(fd int, cl []byte, data []byte) (retCl []byte, retData []byte, flags int, err error) { | |
105 var clp, datap *strbuf | |
106 if len(cl) > 0 { | |
107 clp = &strbuf{ | |
108 Maxlen: int32(len(cl)), | |
109 Buf: (*int8)(unsafe.Pointer(&cl[0])), | |
110 } | |
111 } | |
112 if len(data) > 0 { | |
113 datap = &strbuf{ | |
114 Maxlen: int32(len(data)), | |
115 Buf: (*int8)(unsafe.Pointer(&data[0])), | |
116 } | |
117 } | |
118 | |
119 if err = getmsg(fd, clp, datap, &flags); err != nil { | |
120 return nil, nil, 0, err | |
121 } | |
122 | |
123 if len(cl) > 0 { | |
124 retCl = cl[:clp.Len] | |
125 } | |
126 if len(data) > 0 { | |
127 retData = data[:datap.Len] | |
128 } | |
129 return retCl, retData, flags, nil | |
130 } | |
131 | |
132 func IoctlSetIntRetInt(fd int, req uint, arg int) (int, error) { | |
133 return ioctlRet(fd, req, uintptr(arg)) | |
134 } | |
135 | |
136 func IoctlSetString(fd int, req uint, val string) error { | |
137 bs := make([]byte, len(val)+1) | |
138 copy(bs[:len(bs)-1], val) | |
139 err := ioctl(fd, req, uintptr(unsafe.Pointer(&bs[0]))) | |
140 runtime.KeepAlive(&bs[0]) | |
141 return err | |
142 } | |
143 | |
144 // Lifreq Helpers | |
145 | |
146 func (l *Lifreq) SetName(name string) error { | |
147 if len(name) >= len(l.Name) { | |
148 return fmt.Errorf("name cannot be more than %d characters", len(l.Name)-1) | |
149 } | |
150 for i := range name { | |
151 l.Name[i] = int8(name[i]) | |
152 } | |
153 return nil | |
154 } | |
155 | |
156 func (l *Lifreq) SetLifruInt(d int) { | |
157 *(*int)(unsafe.Pointer(&l.Lifru[0])) = d | |
158 } | |
159 | |
160 func (l *Lifreq) GetLifruInt() int { | |
161 return *(*int)(unsafe.Pointer(&l.Lifru[0])) | |
162 } | |
163 | |
164 func (l *Lifreq) SetLifruUint(d uint) { | |
165 *(*uint)(unsafe.Pointer(&l.Lifru[0])) = d | |
166 } | |
167 | |
168 func (l *Lifreq) GetLifruUint() uint { | |
169 return *(*uint)(unsafe.Pointer(&l.Lifru[0])) | |
170 } | |
171 | |
172 func IoctlLifreq(fd int, req uint, l *Lifreq) error { | |
173 return ioctl(fd, req, uintptr(unsafe.Pointer(l))) | |
174 } | |
175 | |
176 // Strioctl Helpers | |
177 | |
178 func (s *Strioctl) SetInt(i int) { | |
179 s.Len = int32(unsafe.Sizeof(i)) | |
180 s.Dp = (*int8)(unsafe.Pointer(&i)) | |
181 } | |
182 | |
183 func IoctlSetStrioctlRetInt(fd int, req uint, s *Strioctl) (int, error) { | |
184 return ioctlRet(fd, req, uintptr(unsafe.Pointer(s))) | |
185 } |