380
|
1 /* vi: set sw=4 ts=4:
|
|
2 *
|
|
3 * tty.c - Show stdin's terminal name
|
|
4 *
|
|
5 * Copyright 2011 Rob Landley <rob@landley.net>
|
|
6 *
|
|
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/tty.html
|
|
8
|
|
9 USE_TTY(NEWTOY(tty, "s", TOYFLAG_USR|TOYFLAG_BIN))
|
|
10
|
|
11 config TTY
|
|
12 bool "tty"
|
|
13 default y
|
|
14 help
|
|
15 Show filename of terminal connected to stdin.
|
|
16
|
|
17 Prints "not a tty" and exits with nonzero status if no terminal
|
|
18 is connected to stdin.
|
|
19
|
|
20 -s silent mode
|
|
21 */
|
|
22
|
|
23 #include "toys.h"
|
|
24
|
|
25 void tty_main(void)
|
|
26 {
|
|
27 char *tty = ttyname(0);
|
|
28
|
|
29 if (!toys.optflags) puts(tty ? tty : "not a tty");
|
|
30
|
|
31 toys.exitval = !tty;
|
|
32 }
|