github.com/Andyfoo/golang/x/sys@v0.0.0-20190901054642-57c1bf301704/unix/ioctl.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris 6 7 package unix 8 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 } 22 23 // IoctlSetWinsize performs an ioctl on fd with a *Winsize argument. 24 // 25 // To change fd's window size, the req argument should be TIOCSWINSZ. 26 func IoctlSetWinsize(fd int, req uint, value *Winsize) error { 27 // TODO: if we get the chance, remove the req parameter and 28 // hardcode TIOCSWINSZ. 29 err := ioctl(fd, req, uintptr(unsafe.Pointer(value))) 30 runtime.KeepAlive(value) 31 return err 32 } 33 34 // IoctlSetTermios performs an ioctl on fd with a *Termios. 35 // 36 // The req value will usually be TCSETA or TIOCSETA. 37 func IoctlSetTermios(fd int, req uint, value *Termios) error { 38 // TODO: if we get the chance, remove the req parameter. 39 err := ioctl(fd, req, uintptr(unsafe.Pointer(value))) 40 runtime.KeepAlive(value) 41 return err 42 } 43 44 // IoctlGetInt performs an ioctl operation which gets an integer value 45 // from fd, using the specified request number. 46 func IoctlGetInt(fd int, req uint) (int, error) { 47 var value int 48 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) 49 return value, err 50 } 51 52 func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { 53 var value Winsize 54 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) 55 return &value, err 56 } 57 58 func IoctlGetTermios(fd int, req uint) (*Termios, error) { 59 var value Termios 60 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) 61 return &value, err 62 }