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>
34 static void usage
__P ((int status
));
36 /* The name under which this program was run. */
39 /* If nonzero, return an exit status but produce no output. */
42 /* If nonzero, display usage information and exit. */
45 /* If nonzero, 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},
58 main (int argc
, char **argv
)
63 program_name
= argv
[0];
64 setlocale (LC_ALL
, "");
65 bindtextdomain (PACKAGE
, LOCALEDIR
);
70 while ((optc
= getopt_long (argc
, argv
, "s", longopts
, (int *) 0)) != EOF
)
88 printf ("tty - %s\n", version_string
);
104 puts (_("not a tty"));
106 if (ferror (stdout
) || fclose (stdout
) == EOF
)
107 error (3, errno
, _("standard output"));
110 exit (isatty (0) ? 0 : 1);
117 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
121 printf (_("Usage: %s [OPTION]...\n"), program_name
);
123 Print the file name of the terminal connected to standard input.\n\
125 -s, --silent, --quiet print nothing, only return an exit status\n\
126 --help display this help and exit\n\
127 --version output version information and exit\n\