tty.c 565 B

1234567891011121314151617181920212223242526272829
  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. USE_TTY(NEWTOY(tty, "s", TOYFLAG_USR|TOYFLAG_BIN))
  7. config TTY
  8. bool "tty"
  9. default y
  10. help
  11. usage: tty [-s]
  12. Show filename of terminal connected to stdin. If none print "not a tty"
  13. and exit with nonzero status.
  14. -s Silent, exit code only
  15. */
  16. #include "toys.h"
  17. void tty_main(void)
  18. {
  19. char *tty = ttyname(0);
  20. toys.exitval = !tty;
  21. if (!toys.optflags) puts(tty ? : "not a tty");
  22. }