1
2
3
4
5
6
7 package testpty
8
9
15 import "C"
16
17 import "os"
18
19 func open() (pty *os.File, processTTY string, err error) {
20 m, err := C.posix_openpt(C.O_RDWR)
21 if m < 0 {
22 return nil, "", ptyError("posix_openpt", err)
23 }
24 if res, err := C.grantpt(m); res < 0 {
25 C.close(m)
26 return nil, "", ptyError("grantpt", err)
27 }
28 if res, err := C.unlockpt(m); res < 0 {
29 C.close(m)
30 return nil, "", ptyError("unlockpt", err)
31 }
32 processTTY = C.GoString(C.ptsname(m))
33 return os.NewFile(uintptr(m), "pty"), processTTY, nil
34 }
35
View as plain text