mirror of
https://github.com/creack/pty.git
synced 2026-04-01 02:57:06 +09:00
The words "master" and "slave" in this context are both harmful and, as a technical matter, confusing and misleading. It was never my intention to use those terms in this library, but they snuck in while I wasn't paying attention. This change replaces them with "pty" and "tty", respectively, to be consistent with the other files in this package and with the device names on BSD platforms. These terms are not harmful (to the best of my knowledge) and they're more specific. In editing the comment in pty_linux.go, this patch also corrects a factual error. The ioctl argument is not "zero valued", it is a nonzero pointer to the number 0.
34 lines
773 B
Go
34 lines
773 B
Go
package pty
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func open() (pty, tty *os.File, err error) {
|
|
/*
|
|
* from ptm(4):
|
|
* The PTMGET command allocates a free pseudo terminal, changes its
|
|
* ownership to the caller, revokes the access privileges for all previous
|
|
* users, opens the file descriptors for the pty and tty devices and
|
|
* returns them to the caller in struct ptmget.
|
|
*/
|
|
|
|
p, err := os.OpenFile("/dev/ptm", os.O_RDWR|syscall.O_CLOEXEC, 0)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
defer p.Close()
|
|
|
|
var ptm ptmget
|
|
if err := ioctl(p.Fd(), uintptr(ioctl_PTMGET), uintptr(unsafe.Pointer(&ptm))); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
pty = os.NewFile(uintptr(ptm.Cfd), "/dev/ptm")
|
|
tty = os.NewFile(uintptr(ptm.Sfd), "/dev/ptm")
|
|
|
|
return pty, tty, nil
|
|
}
|