1 /* tty -- print the path of the terminal connected to standard input
2 Copyright (C) 1990, 1991 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Displays "not a tty" if stdin is not a terminal.
19 Displays nothing if -s option is given.
20 Exit status 0 if stdin is a tty, 1 if not, 2 if usage error,
23 Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
26 #if defined (CONFIG_BROKETS)
27 /* We use <config.h> instead of "config.h" so that a compilation
28 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
29 (which it would do because it found this file in $srcdir). */
38 #include <sys/types.h>
47 /* The name under which this program was run. */
50 /* If nonzero, return an exit status but produce no output. */
53 /* If non-zero, display usage information and exit. */
56 /* If non-zero, print the version on standard output and exit. */
57 static int show_version;
59 static struct option const longopts[] =
61 {"help", no_argument, &show_help, 1},
62 {"silent", no_argument, NULL, 's'},
63 {"quiet", no_argument, NULL, 's'},
64 {"version", no_argument, &show_version, 1},
76 program_name = argv[0];
79 while ((optc = getopt_long (argc, argv, "s", longopts, (int *) 0)) != EOF)
97 printf ("%s\n", version_string);
115 if (ferror (stdout) || fclose (stdout) == EOF)
116 error (3, errno, "standard output");
119 exit (isatty (0) ? 0 : 1);
126 fprintf (status == 0 ? stdout : stderr, "\
127 Usage: %s [OPTION]...\n\
132 fprintf (stderr, "Try `%s --help' for more information.\n",
138 -s, --silent, --quiet print nothing, only return an exit status\n\
139 --help display this help and exit\n\
140 --version output version information and exit\n\