1 /* tty -- print the path of the terminal connected to standard input
2 Copyright (C) 1990-2000 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>
34 /* The official name of this program (e.g., no `g' prefix). */
35 #define PROGRAM_NAME "tty"
37 #define AUTHORS "David MacKenzie"
39 /* The name under which this program was run. */
42 /* If nonzero, return an exit status but produce no output. */
45 static struct option
const longopts
[] =
47 {"silent", no_argument
, NULL
, 's'},
48 {"quiet", no_argument
, NULL
, 's'},
49 {GETOPT_HELP_OPTION_DECL
},
50 {GETOPT_VERSION_OPTION_DECL
},
58 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
62 printf (_("Usage: %s [OPTION]...\n"), program_name
);
64 Print the file name of the terminal connected to standard input.\n\
66 -s, --silent, --quiet print nothing, only return an exit status\n\
67 --help display this help and exit\n\
68 --version output version information and exit\n\
70 puts (_("\nReport bugs to <bug-sh-utils@gnu.org>."));
76 main (int argc
, char **argv
)
81 program_name
= argv
[0];
82 setlocale (LC_ALL
, "");
83 bindtextdomain (PACKAGE
, LOCALEDIR
);
86 close_stdout_set_status (3);
87 atexit (close_stdout
);
91 while ((optc
= getopt_long (argc
, argv
, "s", longopts
, NULL
)) != -1)
102 case_GETOPT_HELP_CHAR
;
104 case_GETOPT_VERSION_CHAR (PROGRAM_NAME
, AUTHORS
);
112 error (0, 0, _("ignoring all arguments"));
120 puts (_("not a tty"));
123 exit (isatty (0) ? 0 : 1);