changeset 179:4b683759de51

Add tty applet
author Charlie Shepherd <masterdriverz@gentoo.org>
date Fri, 23 Nov 2007 20:49:27 +0000
parents 0e94f5f14f08
children 05a452127fc1
files toys/Config.in toys/toylist.h toys/tty.c
diffstat 3 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/toys/Config.in	Tue Nov 27 01:19:40 2007 -0600
+++ b/toys/Config.in	Fri Nov 23 20:49:27 2007 +0000
@@ -452,6 +452,14 @@
 	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
--- a/toys/toylist.h	Tue Nov 27 01:19:40 2007 -0600
+++ b/toys/toylist.h	Fri Nov 23 20:49:27 2007 +0000
@@ -129,5 +129,6 @@
 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))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/tty.c	Fri Nov 23 20:49:27 2007 +0000
@@ -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;
+}