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_signed.go 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. package unix
  6. import (
  7. "unsafe"
  8. )
  9. // ioctl itself should not be exposed directly, but additional get/set
  10. // functions for specific types are permissible.
  11. // IoctlSetInt performs an ioctl operation which sets an integer value
  12. // on fd, using the specified request number.
  13. func IoctlSetInt(fd int, req int, value int) error {
  14. return ioctl(fd, req, uintptr(value))
  15. }
  16. // IoctlSetPointerInt performs an ioctl operation which sets an
  17. // integer value on fd, using the specified request number. The ioctl
  18. // argument is called with a pointer to the integer value, rather than
  19. // passing the integer value directly.
  20. func IoctlSetPointerInt(fd int, req int, value int) error {
  21. v := int32(value)
  22. return ioctlPtr(fd, req, unsafe.Pointer(&v))
  23. }
  24. // IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
  25. //
  26. // To change fd's window size, the req argument should be TIOCSWINSZ.
  27. func IoctlSetWinsize(fd int, req int, value *Winsize) error {
  28. // TODO: if we get the chance, remove the req parameter and
  29. // hardcode TIOCSWINSZ.
  30. return ioctlPtr(fd, req, unsafe.Pointer(value))
  31. }
  32. // IoctlSetTermios performs an ioctl on fd with a *Termios.
  33. //
  34. // The req value will usually be TCSETA or TIOCSETA.
  35. func IoctlSetTermios(fd int, req int, value *Termios) error {
  36. // TODO: if we get the chance, remove the req parameter.
  37. return ioctlPtr(fd, req, unsafe.Pointer(value))
  38. }
  39. // IoctlGetInt performs an ioctl operation which gets an integer value
  40. // from fd, using the specified request number.
  41. //
  42. // A few ioctl requests use the return value as an output parameter;
  43. // for those, IoctlRetInt should be used instead of this function.
  44. func IoctlGetInt(fd int, req int) (int, error) {
  45. var value int
  46. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  47. return value, err
  48. }
  49. func IoctlGetWinsize(fd int, req int) (*Winsize, error) {
  50. var value Winsize
  51. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  52. return &value, err
  53. }
  54. func IoctlGetTermios(fd int, req int) (*Termios, error) {
  55. var value Termios
  56. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  57. return &value, err
  58. }