try to fix darwin pty

This commit is contained in:
Liam Galvin 2018-08-13 17:39:58 +01:00
parent 31fac53df2
commit 8daef05920
1 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package pty
import (
"errors"
"fmt"
"os"
"syscall"
@ -47,8 +48,16 @@ func getpt() (file *os.File, err error) {
}
func ptsname(file *os.File) (name string, err error) {
n, err := ioctl(file, syscall.TIOCPTYGNAME, 0)
return fmt.Sprintf("/dev/pts/%d", n), err
n := make([]byte, (syscall.TIOCPTYGNAME>>16)&((1<<13)-1))
var err error
n, err = ioctl(file, syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n[0])))
for i, c := range n {
if c == 0 {
return string(n[:i]), nil
}
}
return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
}
func ioctl(file *os.File, command uint, arg int) (int, error) {