diff --git a/tty.c b/tty.c index fcdb21b..6bb77ae 100644 --- a/tty.c +++ b/tty.c @@ -1,24 +1,26 @@ /* See LICENSE file for copyright and license details. */ -#include +#include #include #include -#include +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s\n", argv0); +} int -main(void) +main(int argc, char *argv[]) { char *tty; - if((tty = ttyname(STDIN_FILENO))) { - puts(tty); - return 0; - } - else if(errno == ENOTTY) { - puts("not a tty"); - return 1; - } - else { - perror("ttyname"); - return 2; - } + ARGBEGIN { + default: + usage(); + } ARGEND; + + tty = ttyname(STDIN_FILENO); + puts(tty ? tty : "not a tty"); + return tty ? 0 : 1; }