ioctl_unsigned.go 2.5 KB

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