From 27288b1b7adb8e07ab942b8c6e1f9c0df43fa4ab Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Jan 2020 18:09:27 +0100 Subject: [PATCH] Use golang.org/x/sys/unix for IsTerminal on *BSD Use unix.IoctlGetTermios to implement IsTerminal on *BSD and no longer requires to use the frozen syscall package. --- isatty_bsd.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/isatty_bsd.go b/isatty_bsd.go index 07e9303..711f288 100644 --- a/isatty_bsd.go +++ b/isatty_bsd.go @@ -3,18 +3,12 @@ package isatty -import ( - "syscall" - "unsafe" -) - -const ioctlReadTermios = syscall.TIOCGETA +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.TIOCGETA) + return err == nil } // IsCygwinTerminal return true if the file descriptor is a cygwin or msys2