aboutsummaryrefslogtreecommitdiff
path: root/libgo/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-11-02 16:50:10 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-11-02 16:50:10 +0000
commitc417a082ead98f746d5c289520a3d45f5d1e85f4 (patch)
tree8e902ca727e1f5cf9ac5a0585fec129555e1c14d /libgo/go
parente1bb1accc1c3aeb59741c837b27b3712f56c164d (diff)
downloadgcc-c417a082ead98f746d5c289520a3d45f5d1e85f4.zip
gcc-c417a082ead98f746d5c289520a3d45f5d1e85f4.tar.gz
gcc-c417a082ead98f746d5c289520a3d45f5d1e85f4.tar.bz2
exp/terminal: Use tcgetattr/tcsetattr rather than ioctl.
From-SVN: r180780
Diffstat (limited to 'libgo/go')
-rw-r--r--libgo/go/exp/terminal/terminal.go15
-rw-r--r--libgo/go/syscall/libcall_posix.go6
2 files changed, 13 insertions, 8 deletions
diff --git a/libgo/go/exp/terminal/terminal.go b/libgo/go/exp/terminal/terminal.go
index aacd909..05a8990 100644
--- a/libgo/go/exp/terminal/terminal.go
+++ b/libgo/go/exp/terminal/terminal.go
@@ -17,7 +17,6 @@ package terminal
import (
"os"
"syscall"
- "unsafe"
)
// State contains the state of a terminal.
@@ -28,7 +27,7 @@ type State struct {
// IsTerminal returns true if the given file descriptor is a terminal.
func IsTerminal(fd int) bool {
var termios syscall.Termios
- _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
+ e := syscall.Tcgetattr(fd, &termios)
return e == 0
}
@@ -37,14 +36,14 @@ func IsTerminal(fd int) bool {
// restored.
func MakeRaw(fd int) (*State, os.Error) {
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 e := syscall.Tcgetattr(fd, &oldState.termios); e != 0 {
return nil, os.Errno(e)
}
newState := oldState.termios
newState.Iflag &^= syscall.ISTRIP | syscall.INLCR | syscall.ICRNL | syscall.IGNCR | syscall.IXON | syscall.IXOFF
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 e := syscall.Tcsetattr(fd, syscall.TCSANOW, &newState); e != 0 {
return nil, os.Errno(e)
}
@@ -54,7 +53,7 @@ func MakeRaw(fd int) (*State, os.Error) {
// Restore restores the terminal connected to the given file descriptor to a
// previous state.
func Restore(fd int, state *State) os.Error {
- _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0)
+ e := syscall.Tcsetattr(fd, syscall.TCSANOW, &state.termios)
return os.Errno(e)
}
@@ -63,18 +62,18 @@ func Restore(fd int, state *State) os.Error {
// returned does not include the \n.
func ReadPassword(fd int) ([]byte, os.Error) {
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 e := syscall.Tcgetattr(fd, &oldState); e != 0 {
return nil, os.Errno(e)
}
newState := oldState
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 e := syscall.Tcsetattr(fd, syscall.TCSANOW, &newState); e != 0 {
return nil, os.Errno(e)
}
defer func() {
- syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0)
+ syscall.Tcsetattr(fd, syscall.TCSANOW, &oldState)
}()
var buf [16]byte
diff --git a/libgo/go/syscall/libcall_posix.go b/libgo/go/syscall/libcall_posix.go
index 5d7c98f..87ed4e6 100644
--- a/libgo/go/syscall/libcall_posix.go
+++ b/libgo/go/syscall/libcall_posix.go
@@ -377,3 +377,9 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
tv.Usec = Timeval_usec_t(nsec % 1e9 / 1e3)
return
}
+
+//sysnb Tcgetattr(fd int, p *Termios) (errno int)
+//tcgetattr(fd int, p *Termios) int
+
+//sys Tcsetattr(fd int, actions int, p *Termios) (errno int)
+//tcsetattr(fd int, actions int, p *Termios) int