~sircmpwn/ctools

d5ecc71caaac020de48cf906da4e893c0d09c34e — Adrian Perez de Castro 1 year, 4 months ago 2068266
Implement tty
3 files changed, 27 insertions(+), 1 deletions(-)

M STATUS
M meson.build
A src/tty.c
M STATUS => STATUS +1 -1
@@ 139,7 139,7 @@ T       tput
T       tr
  D     true
T       tsort
T       tty
  D     tty
      N type
      N ulimit
      N umask

M meson.build => meson.build +1 -0
@@ 21,6 21,7 @@ oneshots = [
	'false',
	'nice',
	'true',
	'tty',
	'uname',
	'unlink',
]

A src/tty.c => src/tty.c +25 -0
@@ 0,0 1,25 @@
#include <errno.h>
#include <stdio.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
	if (getopt(argc, argv, "") != -1 || optind != argc) {
		fprintf(stderr, "usage: tty\n");
		return 2;
	}

	char *name = ttyname(STDIN_FILENO);
	if (!name) {
		if (errno == ENOTTY) {
			printf("not a tty\n");
			return 1;
		}
		perror("ttyname");
		return 2;
	}

	printf("%s\n", name);
	return 0;
}