sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit f54c7b4cac5c5ff3251828691a475e40b4f9cb0e
parent 4b30e39348245ef99e3c2030295e54ff01c8cf21
Author: sin <sin@2f30.org>
Date:   Mon,  7 Oct 2013 15:50:41 +0100

Simplify tty(1)

Add a usage line and print "not a tty" for all error cases.

Diffstat:
Mtty.c | 32+++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/tty.c b/tty.c @@ -1,24 +1,26 @@ /* See LICENSE file for copyright and license details. */ -#include <errno.h> +#include <unistd.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> +#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; }