coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

coreutils/src/tty.c (15 lines, 300 B) -rw-r--r-- file download

6a8c357 Jamozed 2020-07-06 23:50:38
0
// tty.c, version 1.1.0
9e5b4df Jamozed 2020-06-27 00:16:43
1
// OMKOV coreutils implementation of POSIX tty
9e5b4df Jamozed 2020-06-27 00:16:43
2
// Copyright (C) 2020, Jakob Wakeling
e2140ec Jamozed 2022-03-06 15:27:45
3
// MIT Licence
9e5b4df Jamozed 2020-06-27 00:16:43
4
6a8c357 Jamozed 2020-07-06 23:50:38
5
#include <unistd.h>
9e5b4df Jamozed 2020-06-27 00:16:43
6
6a8c357 Jamozed 2020-07-06 23:50:38
7
#include <stdio.h>
9e5b4df Jamozed 2020-06-27 00:16:43
8
9e5b4df Jamozed 2020-06-27 00:16:43
9
int main(void) {
6a8c357 Jamozed 2020-07-06 23:50:38
10
	char *tty = ttyname(fileno(stdin));
6a8c357 Jamozed 2020-07-06 23:50:38
11
	if (tty) { puts(tty); return 0; }
6a8c357 Jamozed 2020-07-06 23:50:38
12
	else { printf("not a tty\n"); return 1; }
9e5b4df Jamozed 2020-06-27 00:16:43
13
}
14