logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 1db0ca9fb34b4a196ee7fc8b99abc8e1322a9aa8
parent db2317e7a9b9e67b56458cde2e791dbf62f805c8
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  5 Apr 2021 06:41:36 +0200

bin/tty: New

Diffstat:

Mbin/Makefile.config2+-
Abin/tty.c21+++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/bin/Makefile.config b/bin/Makefile.config @@ -1,2 +1,2 @@ -EXE = args basename date dirname echo lolcat mdate pwd range sizeof sname xcd +EXE = args basename date dirname echo lolcat mdate pwd range sizeof sname tty xcd MAN1 = basename.1 date.1 dirname.1 lolcat.1 sname.1 diff --git a/bin/tty.c b/bin/tty.c @@ -0,0 +1,21 @@ +#include <stdio.h> // puts() +#include <unistd.h> // ttyname(), isatty() + +int +main(void) +{ + if(!isatty(STDIN_FILENO)) { + puts("not a tty"); + return 1; + } + + char *name = ttyname(STDIN_FILENO); + if (!name) { + perror("ttyname"); + return 2; + } + + puts(name); + + return 0; +}