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>
diff --git a/unix/ioctl_signed.go b/unix/ioctl_signed.go
index 5b0759b..be0f3fb 100644
--- a/unix/ioctl_signed.go
+++ b/unix/ioctl_signed.go
@@ -6,9 +6,7 @@
package unix
-import (
- "unsafe"
-)
+import "unsafe"
// ioctl itself should not be exposed directly, but additional get/set
// functions for specific types are permissible.
@@ -28,6 +26,13 @@
return ioctlPtr(fd, req, unsafe.Pointer(&v))
}
+// IoctlSetString performs an ioctl operation which sets a string value
+// on fd, using the specified request number.
+func IoctlSetString(fd int, req int, value string) error {
+ bs := append([]byte(value), 0)
+ return ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
+}
+
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
//
// To change fd's window size, the req argument should be TIOCSWINSZ.
diff --git a/unix/ioctl_unsigned.go b/unix/ioctl_unsigned.go
index 20f470b..f0c2821 100644
--- a/unix/ioctl_unsigned.go
+++ b/unix/ioctl_unsigned.go
@@ -6,9 +6,7 @@
package unix
-import (
- "unsafe"
-)
+import "unsafe"
// ioctl itself should not be exposed directly, but additional get/set
// functions for specific types are permissible.
@@ -28,6 +26,13 @@
return ioctlPtr(fd, req, unsafe.Pointer(&v))
}
+// IoctlSetString performs an ioctl operation which sets a string value
+// on fd, using the specified request number.
+func IoctlSetString(fd int, req uint, value string) error {
+ bs := append([]byte(value), 0)
+ return ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
+}
+
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
//
// To change fd's window size, the req argument should be TIOCSWINSZ.
diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go
index 18a3d9b..a6a2ea0 100644
--- a/unix/syscall_solaris.go
+++ b/unix/syscall_solaris.go
@@ -1052,14 +1052,6 @@
return ioctlRet(fd, req, uintptr(arg))
}
-func IoctlSetString(fd int, req int, val string) error {
- bs := make([]byte, len(val)+1)
- copy(bs[:len(bs)-1], val)
- err := ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
- runtime.KeepAlive(&bs[0])
- return err
-}
-
// Lifreq Helpers
func (l *Lifreq) SetName(name string) error {