1
2
3
4
5 package testpty
6
7 import (
8 "internal/syscall/unix"
9 "os"
10 "syscall"
11 )
12
13 func open() (pty *os.File, processTTY string, err error) {
14 m, err := unix.PosixOpenpt(syscall.O_RDWR)
15 if err != nil {
16 return nil, "", ptyError("posix_openpt", err)
17 }
18 if err := unix.Grantpt(m); err != nil {
19 syscall.Close(m)
20 return nil, "", ptyError("grantpt", err)
21 }
22 if err := unix.Unlockpt(m); err != nil {
23 syscall.Close(m)
24 return nil, "", ptyError("unlockpt", err)
25 }
26 processTTY, err = unix.Ptsname(m)
27 if err != nil {
28 syscall.Close(m)
29 return nil, "", ptyError("ptsname", err)
30 }
31 return os.NewFile(uintptr(m), "pty"), processTTY, nil
32 }
33
View as plain text