diff --git a/Makefile b/Makefile index eb2e58c..b949b55 100644 --- a/Makefile +++ b/Makefile @@ -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 \ 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) BIN = $(SRC:.c=) MAN = $(SRC:.c=.1) diff --git a/tty.1 b/tty.1 new file mode 100644 index 0000000..8e4a919 --- /dev/null +++ b/tty.1 @@ -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) diff --git a/tty.c b/tty.c new file mode 100644 index 0000000..fcdb21b --- /dev/null +++ b/tty.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include + +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; + } +} diff --git a/uname.c b/uname.c index 549669b..75ff52a 100644 --- a/uname.c +++ b/uname.c @@ -41,7 +41,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } if(uname(&u) == -1) - eprintf("uname failed:"); + eprintf("uname:"); if(sflag || !(nflag || rflag || vflag || mflag)) printf("%s ", u.sysname);