vendor/golang.org/x/sys/unix/ioctl.go
changeset 251 1c52a0eeb952
parent 242 2a9ec03fe5a1
child 256 6d9efbef00a9
equal deleted inserted replaced
250:c040f992052f 251:1c52a0eeb952
     4 
     4 
     5 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
     5 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
     6 
     6 
     7 package unix
     7 package unix
     8 
     8 
     9 import "runtime"
     9 import (
       
    10 	"runtime"
       
    11 	"unsafe"
       
    12 )
       
    13 
       
    14 // ioctl itself should not be exposed directly, but additional get/set
       
    15 // functions for specific types are permissible.
       
    16 
       
    17 // IoctlSetInt performs an ioctl operation which sets an integer value
       
    18 // on fd, using the specified request number.
       
    19 func IoctlSetInt(fd int, req uint, value int) error {
       
    20 	return ioctl(fd, req, uintptr(value))
       
    21 }
    10 
    22 
    11 // IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
    23 // IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
    12 //
    24 //
    13 // To change fd's window size, the req argument should be TIOCSWINSZ.
    25 // To change fd's window size, the req argument should be TIOCSWINSZ.
    14 func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
    26 func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
    15 	// TODO: if we get the chance, remove the req parameter and
    27 	// TODO: if we get the chance, remove the req parameter and
    16 	// hardcode TIOCSWINSZ.
    28 	// hardcode TIOCSWINSZ.
    17 	err := ioctlSetWinsize(fd, req, value)
    29 	err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
    18 	runtime.KeepAlive(value)
    30 	runtime.KeepAlive(value)
    19 	return err
    31 	return err
    20 }
    32 }
    21 
    33 
    22 // IoctlSetTermios performs an ioctl on fd with a *Termios.
    34 // IoctlSetTermios performs an ioctl on fd with a *Termios.
    23 //
    35 //
    24 // The req value will usually be TCSETA or TIOCSETA.
    36 // The req value will usually be TCSETA or TIOCSETA.
    25 func IoctlSetTermios(fd int, req uint, value *Termios) error {
    37 func IoctlSetTermios(fd int, req uint, value *Termios) error {
    26 	// TODO: if we get the chance, remove the req parameter.
    38 	// TODO: if we get the chance, remove the req parameter.
    27 	err := ioctlSetTermios(fd, req, value)
    39 	err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
    28 	runtime.KeepAlive(value)
    40 	runtime.KeepAlive(value)
    29 	return err
    41 	return err
    30 }
    42 }
       
    43 
       
    44 // IoctlGetInt performs an ioctl operation which gets an integer value
       
    45 // from fd, using the specified request number.
       
    46 //
       
    47 // A few ioctl requests use the return value as an output parameter;
       
    48 // for those, IoctlRetInt should be used instead of this function.
       
    49 func IoctlGetInt(fd int, req uint) (int, error) {
       
    50 	var value int
       
    51 	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
       
    52 	return value, err
       
    53 }
       
    54 
       
    55 func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
       
    56 	var value Winsize
       
    57 	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
       
    58 	return &value, err
       
    59 }
       
    60 
       
    61 func IoctlGetTermios(fd int, req uint) (*Termios, error) {
       
    62 	var value Termios
       
    63 	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
       
    64 	return &value, err
       
    65 }