mirror of
https://github.com/creack/pty.git
synced 2026-04-01 19:09:48 +09:00
simply remove the broken darwin implementation
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
Pty is a Go package for using unix pseudo-terminals.
|
||||
|
||||
(Note, the Darwin implementation doesn't work. If you
|
||||
are interested in fixing it, I'd appreciate a patch!)
|
||||
(Note, there is only a Linux implementation. I'd appreciate a patch
|
||||
for other systems!)
|
||||
|
||||
## Install
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
package pty
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
sys_TIOCGPTN = 0x80045430
|
||||
sys_TIOCSPTLCK = 0x40045431
|
||||
)
|
||||
|
||||
|
||||
// Opens a pty and its corresponding tty.
|
||||
func Open() (pty, tty *os.File, err os.Error) {
|
||||
p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
sname, err := ptsname(p)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
err = grantpt(p)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
t, err := os.OpenFile(sname, os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return p, t, nil
|
||||
}
|
||||
|
||||
const (
|
||||
ptdev1 = "pqrsPQRS"
|
||||
ptdev2 = "0123456789abcdefghijklmnopqrstuv"
|
||||
)
|
||||
|
||||
func ptsname(f *os.File) (string, os.Error) {
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "/dev/tty" + string([]byte{
|
||||
ptdev1[minor(fi.Rdev)/32],
|
||||
ptdev2[minor(fi.Rdev)%32],
|
||||
}),nil
|
||||
}
|
||||
|
||||
|
||||
func grantpt(f *os.File) os.Error {
|
||||
p, err := os.StartProcess("/bin/ptchown", []string{"/bin/ptchown"}, &os.ProcAttr{Files: []*os.File{f}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w, err := p.Wait(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if w.Exited() && w.ExitStatus() == 0 {
|
||||
return nil
|
||||
}
|
||||
return os.EACCES
|
||||
}
|
||||
|
||||
|
||||
func ioctl(fd int, cmd uint, data *int) os.Error {
|
||||
_, _, e := syscall.Syscall(
|
||||
syscall.SYS_IOCTL,
|
||||
uintptr(fd),
|
||||
uintptr(cmd),
|
||||
uintptr(unsafe.Pointer(data)),
|
||||
)
|
||||
if e != 0 {
|
||||
return os.ENOTTY
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func minor(d uint64) int {
|
||||
return int(d & 0xffffffff)
|
||||
}
|
||||
Reference in New Issue
Block a user