mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-07-03 01:14:35 +08:00
37 lines
649 B
Go
37 lines
649 B
Go
package termios
|
|
|
|
import (
|
|
"errors"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func open_pty_master() (uintptr, error) {
|
|
return open_device("/dev/ptmx")
|
|
}
|
|
|
|
func Ptsname(fd uintptr) (string, error) {
|
|
n := make([]byte, _IOC_PARM_LEN(unix.TIOCPTYGNAME))
|
|
|
|
err := ioctl(fd, unix.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n[0])))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
for i, c := range n {
|
|
if c == 0 {
|
|
return string(n[:i]), nil
|
|
}
|
|
}
|
|
return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
|
|
}
|
|
|
|
func grantpt(fd uintptr) error {
|
|
return ioctl(fd, unix.TIOCPTYGRANT, 0)
|
|
}
|
|
|
|
func unlockpt(fd uintptr) error {
|
|
return ioctl(fd, unix.TIOCPTYUNLK, 0)
|
|
}
|