Refactor tty(1) code and manpage

This commit is contained in:
FRIGN 2015-02-07 22:00:28 +01:00
parent 352eedff58
commit 018d60c6bf
3 changed files with 19 additions and 7 deletions

2
README
View File

@ -71,7 +71,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
= touch no -r = touch no -r
#* tr yes none #* tr yes none
=* true yes none =* true yes none
= tty yes none =* tty yes none
= uname yes none = uname yes none
# unexpand yes none # unexpand yes none
= uniq no -f, -s = uniq no -f, -s

22
tty.1
View File

@ -1,4 +1,4 @@
.Dd January 30, 2015 .Dd February 7, 2015
.Dt TTY 1 .Dt TTY 1
.Os sbase .Os sbase
.Sh NAME .Sh NAME
@ -8,9 +8,21 @@
.Nm .Nm
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
prints the name of the terminal open on stdin. writes the name of the terminal open on stdin to stdout.
.Pp .Sh EXIT STATUS
The status code is 0 if stdin is a terminal, and 1 if not. If an error occurred .Bl -tag -width Ds
the status code is 2. .It 0
stdin is a terminal.
.It 1
stdin is not a terminal.
.It > 1
An error occurred.
.El
.Sh SEE ALSO .Sh SEE ALSO
.Xr ttyname 3 .Xr ttyname 3
.Sh STANDARDS
The
.Nm
utility is compliant with the
.St -p1003.1-2008
specification.

2
tty.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "util.h" #include "util.h"
@ -23,5 +22,6 @@ main(int argc, char *argv[])
tty = ttyname(STDIN_FILENO); tty = ttyname(STDIN_FILENO);
puts(tty ? tty : "not a tty"); puts(tty ? tty : "not a tty");
return tty ? 0 : 1; return tty ? 0 : 1;
} }