ioctl.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
  5. package unix
  6. import (
  7. "runtime"
  8. "unsafe"
  9. )
  10. // ioctl itself should not be exposed directly, but additional get/set
  11. // functions for specific types are permissible.
  12. // IoctlSetInt performs an ioctl operation which sets an integer value
  13. // on fd, using the specified request number.
  14. func IoctlSetInt(fd int, req uint, value int) error {
  15. return ioctl(fd, req, uintptr(value))
  16. }
  17. // IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
  18. //
  19. // To change fd's window size, the req argument should be TIOCSWINSZ.
  20. func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
  21. // TODO: if we get the chance, remove the req parameter and
  22. // hardcode TIOCSWINSZ.
  23. err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  24. runtime.KeepAlive(value)
  25. return err
  26. }
  27. // IoctlSetTermios performs an ioctl on fd with a *Termios.
  28. //
  29. // The req value will usually be TCSETA or TIOCSETA.
  30. func IoctlSetTermios(fd int, req uint, value *Termios) error {
  31. // TODO: if we get the chance, remove the req parameter.
  32. err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  33. runtime.KeepAlive(value)
  34. return err
  35. }
  36. // IoctlGetInt performs an ioctl operation which gets an integer value
  37. // from fd, using the specified request number.
  38. func IoctlGetInt(fd int, req uint) (int, error) {
  39. var value int
  40. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  41. return value, err
  42. }
  43. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  44. var value Winsize
  45. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  46. return &value, err
  47. }
  48. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  49. var value Termios
  50. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  51. return &value, err
  52. }