add tty
This commit is contained in:
parent
164e0c171f
commit
894b42a885
2
Makefile
2
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)
|
||||
|
13
tty.1
Normal file
13
tty.1
Normal 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
24
tty.c
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user