aboutsummaryrefslogtreecommitdiff
path: root/core/tty.c
blob: 7234c052c352bbc80ff16444281585a65bbbbd1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* SPDX-License-Identifier: BSD-3-Clause */
/*
 * Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
 */
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

#define REQ_ERRPRINT /* Require errprint() from ../common/common.h */
#include "../common/common.h"

int main(int, char *argv[]) {
	char *terminalname = ttyname(STDIN_FILENO);
	if (errno == ENOTTY) {
		/* POSIX says that if the stdin isn't a tty then the error shall be 
		 * written to stdout, not stderr.
		 */
		printf("not a tty\n");
		return 1;
	} else if (errno) return errprint(argv[0], NULL, errno);
	printf("%s\n", terminalname);
	return errprint(argv[0], NULL, errno);
}