From 31eb01ae8aac22a4d768418d3cc4da6f903a8694 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Sat, 1 Jun 2013 15:55:05 -0700 Subject: [PATCH] Use uintptr instead of int for Fd --- commands.go | 4 ++-- term/term.go | 14 +++++++------- term/termios_linux.go | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/commands.go b/commands.go index 7dd835856f..977ff12839 100644 --- a/commands.go +++ b/commands.go @@ -1414,7 +1414,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.Fi return err }) - if in != nil && setRawTerminal && term.IsTerminal(int(in.Fd())) && os.Getenv("NORAW") == "" { + if in != nil && setRawTerminal && term.IsTerminal(in.Fd()) && os.Getenv("NORAW") == "" { if oldState, err := term.SetRawTerminal(); err != nil { return err } else { @@ -1433,7 +1433,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.Fi return err } - if !term.IsTerminal(int(os.Stdin.Fd())) { + if !term.IsTerminal(os.Stdin.Fd()) { if err := <-sendStdin; err != nil { return err } diff --git a/term/term.go b/term/term.go index ab90a3ef73..4e29361533 100644 --- a/term/term.go +++ b/term/term.go @@ -128,21 +128,21 @@ func SetWinsize(fd uintptr, ws *Winsize) error { } // IsTerminal returns true if the given file descriptor is a terminal. -func IsTerminal(fd int) bool { +func IsTerminal(fd uintptr) bool { var termios Termios - _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&termios))) + _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&termios))) return err == 0 } // Restore restores the terminal connected to the given file descriptor to a // previous state. -func Restore(fd int, state *State) error { - _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios))) +func Restore(fd uintptr, state *State) error { + _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios))) return err } func SetRawTerminal() (*State, error) { - oldState, err := MakeRaw(int(os.Stdin.Fd())) + oldState, err := MakeRaw(os.Stdin.Fd()) if err != nil { return nil, err } @@ -150,12 +150,12 @@ func SetRawTerminal() (*State, error) { signal.Notify(c, os.Interrupt) go func() { _ = <-c - Restore(int(os.Stdin.Fd()), oldState) + Restore(os.Stdin.Fd(), oldState) os.Exit(0) }() return oldState, err } func RestoreTerminal(state *State) { - Restore(int(os.Stdin.Fd()), state) + Restore(os.Stdin.Fd(), state) } diff --git a/term/termios_linux.go b/term/termios_linux.go index 31a10a307c..7877cb89f8 100644 --- a/term/termios_linux.go +++ b/term/termios_linux.go @@ -13,9 +13,9 @@ const ( // MakeRaw put the terminal connected to the given file descriptor into raw // mode and returns the previous state of the terminal so that it can be // restored. -func MakeRaw(fd int) (*State, error) { +func MakeRaw(fd uintptr) (*State, error) { var oldState State - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { return nil, err } @@ -27,7 +27,7 @@ func MakeRaw(fd int) (*State, error) { newState.Cflag &^= (syscall.CSIZE | syscall.PARENB) newState.Cflag |= syscall.CS8 - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 { + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 { return nil, err } return &oldState, nil