Skip to content

Commit d25a7aa

Browse files
tklausergopherbot
authored andcommitted
unix: add IoctlSetString on all platforms
Currently, only solaris provides IoctlSetString. However, it might be useful on other platforms too, e.g. for SIOCBRADDBR on linux. Change-Id: I19ed47a3e4ed0180ba6777bc193e32bfb61c0506 Reviewed-on: https://go-review.googlesource.com/c/sys/+/720200 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
1 parent 6fb913b commit d25a7aa

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

unix/ioctl_signed.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
package unix
88

9-
import (
10-
"unsafe"
11-
)
9+
import "unsafe"
1210

1311
// ioctl itself should not be exposed directly, but additional get/set
1412
// functions for specific types are permissible.
@@ -28,6 +26,13 @@ func IoctlSetPointerInt(fd int, req int, value int) error {
2826
return ioctlPtr(fd, req, unsafe.Pointer(&v))
2927
}
3028

29+
// IoctlSetString performs an ioctl operation which sets a string value
30+
// on fd, using the specified request number.
31+
func IoctlSetString(fd int, req int, value string) error {
32+
bs := append([]byte(value), 0)
33+
return ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
34+
}
35+
3136
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
3237
//
3338
// To change fd's window size, the req argument should be TIOCSWINSZ.

unix/ioctl_unsigned.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
package unix
88

9-
import (
10-
"unsafe"
11-
)
9+
import "unsafe"
1210

1311
// ioctl itself should not be exposed directly, but additional get/set
1412
// functions for specific types are permissible.
@@ -28,6 +26,13 @@ func IoctlSetPointerInt(fd int, req uint, value int) error {
2826
return ioctlPtr(fd, req, unsafe.Pointer(&v))
2927
}
3028

29+
// IoctlSetString performs an ioctl operation which sets a string value
30+
// on fd, using the specified request number.
31+
func IoctlSetString(fd int, req uint, value string) error {
32+
bs := append([]byte(value), 0)
33+
return ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
34+
}
35+
3136
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
3237
//
3338
// To change fd's window size, the req argument should be TIOCSWINSZ.

unix/syscall_solaris.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,14 +1052,6 @@ func IoctlSetIntRetInt(fd int, req int, arg int) (int, error) {
10521052
return ioctlRet(fd, req, uintptr(arg))
10531053
}
10541054

1055-
func IoctlSetString(fd int, req int, val string) error {
1056-
bs := make([]byte, len(val)+1)
1057-
copy(bs[:len(bs)-1], val)
1058-
err := ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
1059-
runtime.KeepAlive(&bs[0])
1060-
return err
1061-
}
1062-
10631055
// Lifreq Helpers
10641056

10651057
func (l *Lifreq) SetName(name string) error {

0 commit comments

Comments
 (0)