From 801aa5532f36514b1a73de034591c1e7ae324a05 Mon Sep 17 00:00:00 2001 From: Charlie Shepherd Date: Fri, 23 Nov 2007 20:49:27 +0000 Subject: Add tty applet --- toys/Config.in | 8 ++++++++ toys/toylist.h | 1 + toys/tty.c | 13 +++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 toys/tty.c (limited to 'toys') diff --git a/toys/Config.in b/toys/Config.in index e387d245..0c3cb1e3 100644 --- a/toys/Config.in +++ b/toys/Config.in @@ -452,6 +452,14 @@ config TRUE help Return zero. +config TTY + bool "tty" + default y + help + Print the filename of the terminal connected to standard input. + + -s Don't print anything, only return an exit status. + config WHICH bool "which" default y diff --git a/toys/toylist.h b/toys/toylist.h index 87bffed7..d7f30dcb 100644 --- a/toys/toylist.h +++ b/toys/toylist.h @@ -129,5 +129,6 @@ USE_SYNC(NEWTOY(sync, NULL, TOYFLAG_BIN)) USE_TOUCH(NEWTOY(touch, "l#t:r:mca", TOYFLAG_BIN)) USE_TOYSH(NEWTOY(toysh, "c:i", TOYFLAG_BIN)) USE_TRUE(NEWTOY(true, NULL, TOYFLAG_BIN)) +USE_TTY(NEWTOY(tty, "s", TOYFLAG_BIN)) USE_WHICH(NEWTOY(which, "a", TOYFLAG_USR|TOYFLAG_BIN)) USE_YES(NEWTOY(yes, "", TOYFLAG_USR|TOYFLAG_BIN)) diff --git a/toys/tty.c b/toys/tty.c new file mode 100644 index 00000000..c6eeac0a --- /dev/null +++ b/toys/tty.c @@ -0,0 +1,13 @@ +#include "toys.h" + +int tty_main(void) +{ + char *name = ttyname(0); + if (!toys.optflags) { + if (name) + puts(name); + else + puts("Not a tty"); + } + return !name; +} -- cgit v1.2.3