本站源代码
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.

66 lines
2.0KB

  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. // 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 uint, value *Winsize) error {
  21. // TODO: if we get the chance, remove the req parameter and
  22. // hardcode TIOCSWINSZ.
  23. err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  24. runtime.KeepAlive(value)
  25. return err
  26. }
  27. // IoctlSetTermios performs an ioctl on fd with a *Termios.
  28. //
  29. // The req value will usually be TCSETA or TIOCSETA.
  30. func IoctlSetTermios(fd int, req uint, value *Termios) error {
  31. // TODO: if we get the chance, remove the req parameter.
  32. err := ioctl(fd, req, uintptr(unsafe.Pointer(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 uint) (int, error) {
  42. var value int
  43. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  44. return value, err
  45. }
  46. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  47. var value Winsize
  48. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  49. return &value, err
  50. }
  51. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  52. var value Termios
  53. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  54. return &value, err
  55. }
上海开阖软件有限公司 沪ICP备12045867号-1