Update deps with sys/unix changes

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-04-10 13:07:41 -07:00
parent 3db1ea8d07
commit 9e1acba19f
92 changed files with 1766 additions and 1325 deletions

View File

@@ -5,15 +5,16 @@ import "C"
import (
"os"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
// NewPty creates a new pty pair
// The master is returned as the first console and a string
// with the path to the pty slave is returned as the second
func NewPty() (Console, string, error) {
f, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
f, err := os.OpenFile("/dev/ptmx", unix.O_RDWR|unix.O_NOCTTY|unix.O_CLOEXEC, 0)
if err != nil {
return nil, "", err
}
@@ -34,7 +35,7 @@ func NewPty() (Console, string, error) {
type master struct {
f *os.File
termios *syscall.Termios
termios *unix.Termios
}
func (m *master) Read(b []byte) (int, error) {
@@ -52,7 +53,7 @@ func (m *master) Close() error {
func (m *master) Resize(ws WinSize) error {
return ioctl(
m.f.Fd(),
uintptr(syscall.TIOCSWINSZ),
uintptr(unix.TIOCSWINSZ),
uintptr(unsafe.Pointer(&ws)),
)
}
@@ -73,7 +74,7 @@ func (m *master) Reset() error {
}
func (m *master) SetRaw() error {
m.termios = &syscall.Termios{}
m.termios = &unix.Termios{}
if err := tcget(m.f.Fd(), m.termios); err != nil {
return err
}
@@ -87,7 +88,7 @@ func (m *master) Size() (WinSize, error) {
var ws WinSize
if err := ioctl(
m.f.Fd(),
uintptr(syscall.TIOCGWINSZ),
uintptr(unix.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ws)),
); err != nil {
return ws, err
@@ -97,7 +98,7 @@ func (m *master) Size() (WinSize, error) {
// checkConsole checks if the provided file is a console
func checkConsole(f *os.File) error {
var termios syscall.Termios
var termios unix.Termios
if tcget(f.Fd(), &termios) != nil {
return ErrNotAConsole
}

View File

@@ -5,20 +5,21 @@ package console
import (
"fmt"
"os"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
func tcget(fd uintptr, p *syscall.Termios) error {
return ioctl(fd, syscall.TCGETS, uintptr(unsafe.Pointer(p)))
func tcget(fd uintptr, p *unix.Termios) error {
return ioctl(fd, unix.TCGETS, uintptr(unsafe.Pointer(p)))
}
func tcset(fd uintptr, p *syscall.Termios) error {
return ioctl(fd, syscall.TCSETS, uintptr(unsafe.Pointer(p)))
func tcset(fd uintptr, p *unix.Termios) error {
return ioctl(fd, unix.TCSETS, uintptr(unsafe.Pointer(p)))
}
func ioctl(fd, flag, data uintptr) error {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, flag, data); err != 0 {
if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, flag, data); err != 0 {
return err
}
return nil
@@ -28,13 +29,13 @@ func ioctl(fd, flag, data uintptr) error {
// unlockpt should be called before opening the slave side of a pty.
func unlockpt(f *os.File) error {
var u int32
return ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
return ioctl(f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
}
// ptsname retrieves the name of the first available pts for the given master.
func ptsname(f *os.File) (string, error) {
var n int32
if err := ioctl(f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
if err := ioctl(f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
return "", err
}
return fmt.Sprintf("/dev/pts/%d", n), nil
@@ -42,11 +43,11 @@ func ptsname(f *os.File) (string, error) {
func saneTerminal(f *os.File) error {
// Go doesn't have a wrapper for any of the termios ioctls.
var termios syscall.Termios
var termios unix.Termios
if err := tcget(f.Fd(), &termios); err != nil {
return err
}
// Set -onlcr so we don't have to deal with \r.
termios.Oflag &^= syscall.ONLCR
termios.Oflag &^= unix.ONLCR
return tcset(f.Fd(), &termios)
}