Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/dist/test_linux.go

Documentation: cmd/dist

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build linux
     6  // +build linux
     7  
     8  package main
     9  
    10  import (
    11  	"syscall"
    12  	"unsafe"
    13  )
    14  
    15  const ioctlReadTermios = syscall.TCGETS
    16  
    17  // isTerminal reports whether fd is a terminal.
    18  func isTerminal(fd uintptr) bool {
    19  	var termios syscall.Termios
    20  	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
    21  	return err == 0
    22  }
    23  
    24  func init() {
    25  	stdOutErrAreTerminals = func() bool {
    26  		return isTerminal(1) && isTerminal(2)
    27  	}
    28  }
    29  

View as plain text