Browse Source

Merge pull request #25 from tklauser/linux-use-x-sys-unix

use golang.org/x/sys/unix for IsTerminal on Linux
mattn 6 years ago
parent
commit
c6c56f60d8
2 changed files with 4 additions and 35 deletions
  1. 4 10
      isatty_linux.go
  2. 0 25
      isatty_linux_ppc64x.go

+ 4 - 10
isatty_linux.go

@@ -1,20 +1,14 @@
 // +build linux
-// +build !appengine,!ppc64,!ppc64le
+// +build !appengine
 
 package isatty
 
-import (
-	"syscall"
-	"unsafe"
-)
-
-const ioctlReadTermios = syscall.TCGETS
+import "golang.org/x/sys/unix"
 
 // IsTerminal return true if the file descriptor is terminal.
 func IsTerminal(fd uintptr) bool {
-	var termios syscall.Termios
-	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
-	return err == 0
+	_, err := unix.IoctlGetTermios(int(fd), unix.TCGETS)
+	return err == nil
 }
 
 // IsCygwinTerminal return true if the file descriptor is a cygwin or msys2

+ 0 - 25
isatty_linux_ppc64x.go

@@ -1,25 +0,0 @@
-// +build linux
-// +build ppc64 ppc64le
-
-package isatty
-
-import (
-	"unsafe"
-
-	syscall "golang.org/x/sys/unix"
-)
-
-const ioctlReadTermios = syscall.TCGETS
-
-// IsTerminal return true if the file descriptor is terminal.
-func IsTerminal(fd uintptr) bool {
-	var termios syscall.Termios
-	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
-	return err == 0
-}
-
-// IsCygwinTerminal return true if the file descriptor is a cygwin or msys2
-// terminal. This is also always false on this environment.
-func IsCygwinTerminal(fd uintptr) bool {
-	return false
-}