1 /* tty -- print the path of the terminal connected to standard input
2 Copyright (C) 90, 91, 92, 93, 94, 1995 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>. */
28 #include <sys/types.h>
36 /* The name under which this program was run. */
39 /* If nonzero, return an exit status but produce no output. */
42 /* If non-zero, display usage information and exit. */
45 /* If non-zero, print the version on standard output and exit. */
46 static int show_version
;
48 static struct option
const longopts
[] =
50 {"help", no_argument
, &show_help
, 1},
51 {"silent", no_argument
, NULL
, 's'},
52 {"quiet", no_argument
, NULL
, 's'},
53 {"version", no_argument
, &show_version
, 1},
65 program_name
= argv
[0];
68 while ((optc
= getopt_long (argc
, argv
, "s", longopts
, (int *) 0)) != EOF
)
86 printf ("tty - %s\n", version_string
);
104 if (ferror (stdout
) || fclose (stdout
) == EOF
)
105 error (3, errno
, "standard output");
108 exit (isatty (0) ? 0 : 1);
116 fprintf (stderr
, "Try `%s --help' for more information.\n",
120 printf ("Usage: %s [OPTION]...\n", program_name
);
122 Print the file name of the terminal connected to standard input.\n\
124 -s, --silent, --quiet print nothing, only return an exit status\n\
125 --help display this help and exit\n\
126 --version output version information and exit\n\