1 /* tty -- print the path of the terminal connected to standard input
2 Copyright (C) 90,91,92,93,94,95,96,1997 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 Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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>
33 static void usage PARAMS ((int status));
35 /* The name under which this program was run. */
38 /* If nonzero, return an exit status but produce no output. */
41 /* If nonzero, display usage information and exit. */
44 /* If nonzero, print the version on standard output and exit. */
45 static int show_version;
47 static struct option const longopts[] =
49 {"help", no_argument, &show_help, 1},
50 {"silent", no_argument, NULL, 's'},
51 {"quiet", no_argument, NULL, 's'},
52 {"version", no_argument, &show_version, 1},
57 main (int argc, char **argv)
62 program_name = argv[0];
63 setlocale (LC_ALL, "");
64 bindtextdomain (PACKAGE, LOCALEDIR);
69 while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1)
87 printf ("tty (%s) %s\n", GNU_PACKAGE, VERSION);
103 puts (_("not a tty"));
105 if (ferror (stdout) || fclose (stdout) == EOF)
106 error (3, errno, _("standard output"));
109 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\
128 puts (_("\nReport bugs to <bug-sh-utils@gnu.org>."));