• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* tty.c - Show stdin's terminal name
2  *
3  * Copyright 2011 Rob Landley <rob@landley.net>
4  *
5  * See http://opengroup.org/onlinepubs/9699919799/utilities/tty.html
6 
7 USE_TTY(NEWTOY(tty, "s", TOYFLAG_USR|TOYFLAG_BIN))
8 
9 config TTY
10   bool "tty"
11   default y
12   help
13     usage: tty [-s]
14 
15     Show filename of terminal connected to stdin. If none print "not a tty"
16     and exit with nonzero status.
17 
18     -s	Silent, exit code only
19 */
20 
21 #include "toys.h"
22 
tty_main(void)23 void tty_main(void)
24 {
25   char *tty = ttyname(0);
26 
27   toys.exitval = !tty;
28   if (!toys.optflags) puts(tty ? : "not a tty");
29 }
30