toybox/toys/posix/tty.c
<<
>>
Prefs
   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
   7USE_TTY(NEWTOY(tty, "s", TOYFLAG_USR|TOYFLAG_BIN))
   8
   9config TTY
  10  bool "tty"
  11  default y
  12  help
  13    usage: tty [-s]
  14
  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, exit code only
  21*/
  22
  23#include "toys.h"
  24
  25void 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}
  33