CONTENTS | INDEX | PREV | NEXT

 isatty 

 NAME
  isatty - Is a file descriptor a TTY ?

 SYNOPSIS
  int r = isatty(fd);
  int fd;

 FUNCTION
  Returns TRUE (1) if the file descriptor is associated with a
  console, FALSE (0) if not, or -1 if an error condition occurs
  (such as illegal file descriptor).

 NOTE
  the standard input (0), standard output (1), and standard error (2)
  can all return different values for isatty() depending on how the
  program is redirected.  A program whos standard in and standard out
  is redirected may still have a standard error that is connected to
  the console.

  refer to the file_descriptor manual page for general information

  Unlike file pointers and file handles, the file descriptor is
  checked for validity and will simply return an error if illegal.

 EXAMPLE
  #include <stdio.h>

  main()
  {
      if (isatty(1)) {
      puts("input is a TTY");
      } else {
      puts("input is not a TTY");
      }
  }

  1> testprg
  input is a TTY
  1> echo >t:x        ; create dummy file
  1> testprg <t:x
  input is not a TTY
  1>

 INPUTS
  int fd;     file descriptor

 RESULTS
  int r;      result, 1 if a tty, 0 if not, or -1 if error