pty_darwin.go 649 B

123456789101112131415161718192021222324252627282930313233343536
  1. package termios
  2. import (
  3. "errors"
  4. "unsafe"
  5. "golang.org/x/sys/unix"
  6. )
  7. func open_pty_master() (uintptr, error) {
  8. return open_device("/dev/ptmx")
  9. }
  10. func Ptsname(fd uintptr) (string, error) {
  11. n := make([]byte, _IOC_PARM_LEN(unix.TIOCPTYGNAME))
  12. err := ioctl(fd, unix.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n[0])))
  13. if err != nil {
  14. return "", err
  15. }
  16. for i, c := range n {
  17. if c == 0 {
  18. return string(n[:i]), nil
  19. }
  20. }
  21. return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
  22. }
  23. func grantpt(fd uintptr) error {
  24. return ioctl(fd, unix.TIOCPTYGRANT, 0)
  25. }
  26. func unlockpt(fd uintptr) error {
  27. return ioctl(fd, unix.TIOCPTYUNLK, 0)
  28. }