diff options
author | Ferass El Hafidi <vitali64pmemail@protonmail.com> | 2023-02-19 11:56:31 +0100 |
---|---|---|
committer | Ferass El Hafidi <vitali64pmemail@protonmail.com> | 2023-02-19 11:56:31 +0100 |
commit | e36a5982bd7d73ad5623fb3b91c41ab6f7bd6ff8 (patch) | |
tree | 4b05063ec4d4da44acf40eda09f1241596f3df14 | |
parent | 273e5a0cc35a16aaa0652da651785e72dd25d10d (diff) | |
download | fases-e36a5982bd7d73ad5623fb3b91c41ab6f7bd6ff8.tar.gz fases-e36a5982bd7d73ad5623fb3b91c41ab6f7bd6ff8.zip |
core/: tty
Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
-rw-r--r-- | config.mk | 1 | ||||
-rw-r--r-- | core/tty.c | 21 |
2 files changed, 22 insertions, 0 deletions
@@ -32,6 +32,7 @@ CORE=\ tail\ test\ true\ + tty\ uname\ unlink\ wc diff --git a/core/tty.c b/core/tty.c new file mode 100644 index 0000000..2e663e1 --- /dev/null +++ b/core/tty.c @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +#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 0; +} |