github.com/zxy12/go_duplicate_1_12@v0.0.0-20200217043740-b1636fc0368b/src/cmd/dist/test_linux.go (about)

     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  // +build linux
     6  
     7  package main
     8  
     9  import (
    10  	"syscall"
    11  	"unsafe"
    12  )
    13  
    14  const ioctlReadTermios = syscall.TCGETS
    15  
    16  // isTerminal reports whether fd is a terminal.
    17  func isTerminal(fd uintptr) bool {
    18  	var termios syscall.Termios
    19  	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
    20  	return err == 0
    21  }
    22  
    23  func init() {
    24  	stdOutErrAreTerminals = func() bool {
    25  		return isTerminal(1) && isTerminal(2)
    26  	}
    27  }