mirror of
https://github.com/golang/go
synced 2024-11-20 00:14:44 -07:00
exp/terminal: fix build after os.Errno changes
Also include exp/terminal in linux build so such failures are noticed. R=rsc CC=golang-dev https://golang.org/cl/5416044
This commit is contained in:
parent
4a2d30e13b
commit
558d055352
@ -188,6 +188,7 @@ DIRS=\
|
|||||||
ifeq ($(GOOS),linux)
|
ifeq ($(GOOS),linux)
|
||||||
DIRS+=\
|
DIRS+=\
|
||||||
exp/inotify\
|
exp/inotify\
|
||||||
|
exp/terminal\
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ package terminal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@ -29,8 +28,8 @@ type State struct {
|
|||||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||||
func IsTerminal(fd int) bool {
|
func IsTerminal(fd int) bool {
|
||||||
var termios syscall.Termios
|
var termios syscall.Termios
|
||||||
_, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
||||||
return e == 0
|
return err == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeRaw put the terminal connected to the given file descriptor into raw
|
// MakeRaw put the terminal connected to the given file descriptor into raw
|
||||||
@ -38,15 +37,15 @@ func IsTerminal(fd int) bool {
|
|||||||
// restored.
|
// restored.
|
||||||
func MakeRaw(fd int) (*State, error) {
|
func MakeRaw(fd int) (*State, error) {
|
||||||
var oldState State
|
var oldState State
|
||||||
if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); e != 0 {
|
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
|
||||||
return nil, os.Errno(e)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
newState := oldState.termios
|
newState := oldState.termios
|
||||||
newState.Iflag &^= syscall.ISTRIP | syscall.INLCR | syscall.ICRNL | syscall.IGNCR | syscall.IXON | syscall.IXOFF
|
newState.Iflag &^= syscall.ISTRIP | syscall.INLCR | syscall.ICRNL | syscall.IGNCR | syscall.IXON | syscall.IXOFF
|
||||||
newState.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.ISIG
|
newState.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.ISIG
|
||||||
if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 {
|
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 {
|
||||||
return nil, os.Errno(e)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &oldState, nil
|
return &oldState, nil
|
||||||
@ -55,8 +54,8 @@ func MakeRaw(fd int) (*State, error) {
|
|||||||
// Restore restores the terminal connected to the given file descriptor to a
|
// Restore restores the terminal connected to the given file descriptor to a
|
||||||
// previous state.
|
// previous state.
|
||||||
func Restore(fd int, state *State) error {
|
func Restore(fd int, state *State) error {
|
||||||
_, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
|
||||||
return os.Errno(e)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadPassword reads a line of input from a terminal without local echo. This
|
// ReadPassword reads a line of input from a terminal without local echo. This
|
||||||
@ -64,14 +63,14 @@ func Restore(fd int, state *State) error {
|
|||||||
// returned does not include the \n.
|
// returned does not include the \n.
|
||||||
func ReadPassword(fd int) ([]byte, error) {
|
func ReadPassword(fd int) ([]byte, error) {
|
||||||
var oldState syscall.Termios
|
var oldState syscall.Termios
|
||||||
if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 {
|
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); err != 0 {
|
||||||
return nil, os.Errno(e)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
newState := oldState
|
newState := oldState
|
||||||
newState.Lflag &^= syscall.ECHO
|
newState.Lflag &^= syscall.ECHO
|
||||||
if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 {
|
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 {
|
||||||
return nil, os.Errno(e)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -81,9 +80,9 @@ func ReadPassword(fd int) ([]byte, error) {
|
|||||||
var buf [16]byte
|
var buf [16]byte
|
||||||
var ret []byte
|
var ret []byte
|
||||||
for {
|
for {
|
||||||
n, errno := syscall.Read(fd, buf[:])
|
n, err := syscall.Read(fd, buf[:])
|
||||||
if errno != 0 {
|
if err != nil {
|
||||||
return nil, os.Errno(errno)
|
return nil, err
|
||||||
}
|
}
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
if len(ret) == 0 {
|
if len(ret) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user