You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ioctl.go 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // IoctlSetPointerInt performs an ioctl operation which sets an
  18. // integer value on fd, using the specified request number. The ioctl
  19. // argument is called with a pointer to the integer value, rather than
  20. // passing the integer value directly.
  21. func IoctlSetPointerInt(fd int, req uint, value int) error {
  22. v := int32(value)
  23. return ioctl(fd, req, uintptr(unsafe.Pointer(&v)))
  24. }
  25. // IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
  26. //
  27. // To change fd's window size, the req argument should be TIOCSWINSZ.
  28. func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
  29. // TODO: if we get the chance, remove the req parameter and
  30. // hardcode TIOCSWINSZ.
  31. err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  32. runtime.KeepAlive(value)
  33. return err
  34. }
  35. // IoctlSetTermios performs an ioctl on fd with a *Termios.
  36. //
  37. // The req value will usually be TCSETA or TIOCSETA.
  38. func IoctlSetTermios(fd int, req uint, value *Termios) error {
  39. // TODO: if we get the chance, remove the req parameter.
  40. err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  41. runtime.KeepAlive(value)
  42. return err
  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. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  55. var value Winsize
  56. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  57. return &value, err
  58. }
  59. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  60. var value Termios
  61. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  62. return &value, err
  63. }