2017-05-20 01:18:43 +08:00
|
|
|
package console
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2017-09-25 23:53:28 +08:00
|
|
|
const (
|
|
|
|
cmdTcGet = unix.TIOCGETA
|
|
|
|
cmdTcSet = unix.TIOCSETA
|
|
|
|
)
|
2017-05-20 01:18:43 +08:00
|
|
|
|
|
|
|
// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
|
|
|
|
// unlockpt should be called before opening the slave side of a pty.
|
|
|
|
// This does not exist on FreeBSD, it does not allocate controlling terminals on open
|
|
|
|
func unlockpt(f *os.File) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ptsname retrieves the name of the first available pts for the given master.
|
|
|
|
func ptsname(f *os.File) (string, error) {
|
2017-09-25 23:53:28 +08:00
|
|
|
n, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCGPTN)
|
|
|
|
if err != nil {
|
2017-05-20 01:18:43 +08:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("/dev/pts/%d", n), nil
|
|
|
|
}
|