mirror of
git://git.suckless.org/sbase
synced 2024-12-24 07:53:08 +00:00
Simplify tty(1)
Add a usage line and print "not a tty" for all error cases.
This commit is contained in:
parent
4b30e39348
commit
f54c7b4cac
32
tty.c
32
tty.c
@ -1,24 +1,26 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
#include <errno.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include "util.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
eprintf("usage: %s\n", argv0);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *tty;
|
char *tty;
|
||||||
|
|
||||||
if((tty = ttyname(STDIN_FILENO))) {
|
ARGBEGIN {
|
||||||
puts(tty);
|
default:
|
||||||
return 0;
|
usage();
|
||||||
}
|
} ARGEND;
|
||||||
else if(errno == ENOTTY) {
|
|
||||||
puts("not a tty");
|
tty = ttyname(STDIN_FILENO);
|
||||||
return 1;
|
puts(tty ? tty : "not a tty");
|
||||||
}
|
return tty ? 0 : 1;
|
||||||
else {
|
|
||||||
perror("ttyname");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user