ioctl_zos.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2020 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 zos && s390x
  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 int, 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 int, value *Winsize) error {
  21. // TODO: if we get the chance, remove the req parameter and
  22. // hardcode TIOCSWINSZ.
  23. return ioctlPtr(fd, req, unsafe.Pointer(value))
  24. }
  25. // IoctlSetTermios performs an ioctl on fd with a *Termios.
  26. //
  27. // The req value is expected to be TCSETS, TCSETSW, or TCSETSF
  28. func IoctlSetTermios(fd int, req int, value *Termios) error {
  29. if (req != TCSETS) && (req != TCSETSW) && (req != TCSETSF) {
  30. return ENOSYS
  31. }
  32. err := Tcsetattr(fd, int(req), 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. //
  39. // A few ioctl requests use the return value as an output parameter;
  40. // for those, IoctlRetInt should be used instead of this function.
  41. func IoctlGetInt(fd int, req int) (int, error) {
  42. var value int
  43. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  44. return value, err
  45. }
  46. func IoctlGetWinsize(fd int, req int) (*Winsize, error) {
  47. var value Winsize
  48. err := ioctlPtr(fd, req, unsafe.Pointer(&value))
  49. return &value, err
  50. }
  51. // IoctlGetTermios performs an ioctl on fd with a *Termios.
  52. //
  53. // The req value is expected to be TCGETS
  54. func IoctlGetTermios(fd int, req int) (*Termios, error) {
  55. var value Termios
  56. if req != TCGETS {
  57. return &value, ENOSYS
  58. }
  59. err := Tcgetattr(fd, &value)
  60. return &value, err
  61. }