ioctl_bsd.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //go:build darwin || dragonfly || freebsd || netbsd || openbsd
  2. // +build darwin dragonfly freebsd netbsd openbsd
  3. package pty
  4. // from <sys/ioccom.h>
  5. const (
  6. _IOC_VOID uintptr = 0x20000000
  7. _IOC_OUT uintptr = 0x40000000
  8. _IOC_IN uintptr = 0x80000000
  9. _IOC_IN_OUT uintptr = _IOC_OUT | _IOC_IN
  10. _IOC_DIRMASK = _IOC_VOID | _IOC_OUT | _IOC_IN
  11. _IOC_PARAM_SHIFT = 13
  12. _IOC_PARAM_MASK = (1 << _IOC_PARAM_SHIFT) - 1
  13. )
  14. func _IOC_PARM_LEN(ioctl uintptr) uintptr {
  15. return (ioctl >> 16) & _IOC_PARAM_MASK
  16. }
  17. func _IOC(inout uintptr, group byte, ioctl_num uintptr, param_len uintptr) uintptr {
  18. return inout | (param_len&_IOC_PARAM_MASK)<<16 | uintptr(group)<<8 | ioctl_num
  19. }
  20. func _IO(group byte, ioctl_num uintptr) uintptr {
  21. return _IOC(_IOC_VOID, group, ioctl_num, 0)
  22. }
  23. func _IOR(group byte, ioctl_num uintptr, param_len uintptr) uintptr {
  24. return _IOC(_IOC_OUT, group, ioctl_num, param_len)
  25. }
  26. func _IOW(group byte, ioctl_num uintptr, param_len uintptr) uintptr {
  27. return _IOC(_IOC_IN, group, ioctl_num, param_len)
  28. }
  29. func _IOWR(group byte, ioctl_num uintptr, param_len uintptr) uintptr {
  30. return _IOC(_IOC_IN_OUT, group, ioctl_num, param_len)
  31. }