annotate toys/tty.c @ 380:782859fadd20

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