Ver código fonte

unix: document IoctlSetWinsize and IoctlSetTermios and fix pointer lifetime

Change-Id: I42e59149e58bd928d9beb2c6665ce186b377d2a1
Reviewed-on: https://go-review.googlesource.com/125640
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Brad Fitzpatrick 7 anos atrás
pai
commit
e072cadbbd

+ 30 - 0
unix/ioctl.go

@@ -0,0 +1,30 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
+
+package unix
+
+import "runtime"
+
+// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
+//
+// To change fd's window size, the req argument should be TIOCSWINSZ.
+func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+	// TODO: if we get the chance, remove the req parameter and
+	// hardcode TIOCSWINSZ.
+	err := ioctlSetWinsize(fd, req, value)
+	runtime.KeepAlive(value)
+	return err
+}
+
+// IoctlSetTermios performs an ioctl on fd with a *Termios.
+//
+// The req value will usually be TCSETA or TIOCSETA.
+func IoctlSetTermios(fd int, req uint, value *Termios) error {
+	// TODO: if we get the chance, remove the req parameter.
+	err := ioctlSetTermios(fd, req, value)
+	runtime.KeepAlive(value)
+	return err
+}

+ 2 - 2
unix/syscall_darwin.go

@@ -313,11 +313,11 @@ func IoctlSetInt(fd int, req uint, value int) error {
 	return ioctl(fd, req, uintptr(value))
 	return ioctl(fd, req, uintptr(value))
 }
 }
 
 
-func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 
-func IoctlSetTermios(fd int, req uint, value *Termios) error {
+func ioctlSetTermios(fd int, req uint, value *Termios) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 

+ 2 - 2
unix/syscall_dragonfly.go

@@ -143,11 +143,11 @@ func IoctlSetInt(fd int, req uint, value int) error {
 	return ioctl(fd, req, uintptr(value))
 	return ioctl(fd, req, uintptr(value))
 }
 }
 
 
-func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 
-func IoctlSetTermios(fd int, req uint, value *Termios) error {
+func ioctlSetTermios(fd int, req uint, value *Termios) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 

+ 2 - 2
unix/syscall_freebsd.go

@@ -364,11 +364,11 @@ func IoctlSetInt(fd int, req uint, value int) error {
 	return ioctl(fd, req, uintptr(value))
 	return ioctl(fd, req, uintptr(value))
 }
 }
 
 
-func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 
-func IoctlSetTermios(fd int, req uint, value *Termios) error {
+func ioctlSetTermios(fd int, req uint, value *Termios) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 

+ 2 - 2
unix/syscall_linux.go

@@ -61,11 +61,11 @@ func IoctlSetInt(fd int, req uint, value int) error {
 	return ioctl(fd, req, uintptr(value))
 	return ioctl(fd, req, uintptr(value))
 }
 }
 
 
-func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 
-func IoctlSetTermios(fd int, req uint, value *Termios) error {
+func ioctlSetTermios(fd int, req uint, value *Termios) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 

+ 2 - 2
unix/syscall_netbsd.go

@@ -145,11 +145,11 @@ func IoctlSetInt(fd int, req uint, value int) error {
 	return ioctl(fd, req, uintptr(value))
 	return ioctl(fd, req, uintptr(value))
 }
 }
 
 
-func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 
-func IoctlSetTermios(fd int, req uint, value *Termios) error {
+func ioctlSetTermios(fd int, req uint, value *Termios) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 

+ 2 - 2
unix/syscall_openbsd.go

@@ -113,11 +113,11 @@ func IoctlSetInt(fd int, req uint, value int) error {
 	return ioctl(fd, req, uintptr(value))
 	return ioctl(fd, req, uintptr(value))
 }
 }
 
 
-func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 
-func IoctlSetTermios(fd int, req uint, value *Termios) error {
+func ioctlSetTermios(fd int, req uint, value *Termios) error {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 

+ 2 - 2
unix/syscall_solaris.go

@@ -540,11 +540,11 @@ func IoctlSetInt(fd int, req uint, value int) (err error) {
 	return ioctl(fd, req, uintptr(value))
 	return ioctl(fd, req, uintptr(value))
 }
 }
 
 
-func IoctlSetWinsize(fd int, req uint, value *Winsize) (err error) {
+func ioctlSetWinsize(fd int, req uint, value *Winsize) (err error) {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }
 
 
-func IoctlSetTermios(fd int, req uint, value *Termios) (err error) {
+func ioctlSetTermios(fd int, req uint, value *Termios) (err error) {
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 }
 }