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.
 
 

71 lines
2.2 KiB

  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. //go:build aix || solaris
  5. // +build aix solaris
  6. package unix
  7. import (
  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 int, 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 int, value int) error {
  22. v := int32(value)
  23. return ioctlPtr(fd, req, 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 int, value *Winsize) error {
  29. // TODO: if we get the chance, remove the req parameter and
  30. // hardcode TIOCSWINSZ.
  31. return ioctlPtr(fd, req, unsafe.Pointer(value))
  32. }
  33. // IoctlSetTermios performs an ioctl on fd with a *Termios.
  34. //
  35. // The req value will usually be TCSETA or TIOCSETA.
  36. func IoctlSetTermios(fd int, req int, value *Termios) error {
  37. // TODO: if we get the chance, remove the req parameter.
  38. return ioctlPtr(fd, req, unsafe.Pointer(value))
  39. }
  40. // IoctlGetInt performs an ioctl operation which gets an integer value
  41. // from fd, using the specified request number.
  42. //
  43. // A few ioctl requests use the return value as an output parameter;
  44. // for those, IoctlRetInt should be used instead of this function.
  45. func IoctlGetInt(fd int, req int) (int, error) {
  46. var value int
  47. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  48. return value, err
  49. }
  50. func IoctlGetWinsize(fd int, req int) (*Winsize, error) {
  51. var value Winsize
  52. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  53. return &value, err
  54. }
  55. func IoctlGetTermios(fd int, req int) (*Termios, error) {
  56. var value Termios
  57. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  58. return &value, err
  59. }