sbase

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

commit 894b42a8850b43f4cd84505114532eeac6f1925a
parent 164e0c171fd4a72bdd427e3e4c0f1e84777d6b87
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Thu,  2 Jun 2011 21:15:35 +0100

add tty
Diffstat:
MMakefile | 2+-
Atty.1 | 13+++++++++++++
Atty.c | 24++++++++++++++++++++++++
Muname.c | 2+-
4 files changed, 39 insertions(+), 2 deletions(-)

diff --git 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 @@ -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 @@ -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; + } +} diff --git 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);