This commit is contained in:
Connor Lane Smith 2011-06-02 21:15:35 +01:00
parent 164e0c171f
commit 894b42a885
4 changed files with 39 additions and 2 deletions

View File

@ -6,7 +6,7 @@ LIB = util/afgets.o util/agetcwd.o util/concat.o util/enmasse.o util/eprintf.o \
SRC = basename.c cat.c chmod.c chown.c date.c dirname.c echo.c false.c grep.c \ SRC = basename.c cat.c chmod.c chown.c date.c dirname.c echo.c false.c grep.c \
head.c ln.c ls.c mkdir.c mkfifo.c nl.c pwd.c rm.c sleep.c sort.c tail.c \ head.c ln.c ls.c mkdir.c mkfifo.c nl.c pwd.c rm.c sleep.c sort.c tail.c \
tee.c touch.c true.c uname.c wc.c tee.c touch.c true.c tty.c uname.c wc.c
OBJ = $(SRC:.c=.o) $(LIB) OBJ = $(SRC:.c=.o) $(LIB)
BIN = $(SRC:.c=) BIN = $(SRC:.c=)
MAN = $(SRC:.c=.1) MAN = $(SRC:.c=.1)

13
tty.1 Normal file
View File

@ -0,0 +1,13 @@
.TH TTY 1 sbase\-VERSION
.SH NAME
tty \- print terminal name
.SH SYNOPSIS
.B tty
.SH DESCRIPTION
.B tty
prints the name of the terminal open on stdin.
.P
The status code is 0 if stdin is a terminal, and 1 if not. If an error occurred
the status code is 2.
.SH SEE ALSO
.IR ttyname (3)

24
tty.c Normal file
View File

@ -0,0 +1,24 @@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main(void)
{
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;
}
}

View File

@ -41,7 +41,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(uname(&u) == -1) if(uname(&u) == -1)
eprintf("uname failed:"); eprintf("uname:");
if(sflag || !(nflag || rflag || vflag || mflag)) if(sflag || !(nflag || rflag || vflag || mflag))
printf("%s ", u.sysname); printf("%s ", u.sysname);