tty.c (339B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#define _XOPEN_SOURCE 700 #include <errno.h> #include <stdio.h> #include <unistd.h> int main(void) { char *tty = ttyname(0); if (tty == NULL) { if (errno != ENOTTY) { perror("tty"); return 2; } printf("not a tty\n"); return 1; } printf("%s\n", tty); return 0; }