Skip to content

Commit

Permalink
Use golang.org/x/sys/unix for IsTerminal on *BSD
Browse files Browse the repository at this point in the history
Use unix.IoctlGetTermios to implement IsTerminal on *BSD and no longer
requires to use the frozen syscall package.
  • Loading branch information
tklauser committed Jan 21, 2020
1 parent 65118e8 commit 27288b1
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions isatty_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 27288b1

Please sign in to comment.