This uses ioctl syscalls or appropriate alternative, to detect if stdin/out/err are character devices or not. This caches the result, to ensure performance is ok at runtime as executing stat can approach microsecond overhead. Signed-off-by: Adrian Cole <adrian@tetrate.io>
15 lines
281 B
Go
15 lines
281 B
Go
//go:build darwin || linux || freebsd
|
|
|
|
package platform
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func isTerminal(fd uintptr) bool {
|
|
var val syscall.Termios
|
|
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&val)), 0, 0, 0)
|
|
return err == 0
|
|
}
|