Skip to content

Instantly share code, notes, and snippets.

@merthmagic
Created February 20, 2020 16:16
Show Gist options
  • Select an option

  • Save merthmagic/1a0ce995ab0da6c4173d624dc05b088b to your computer and use it in GitHub Desktop.

Select an option

Save merthmagic/1a0ce995ab0da6c4173d624dc05b088b to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdio.h>
void print_tty(char *name,FILE *f){
printf("%s (fileno %d): ",name,fileno(f));
if(isatty(fileno(f)))
printf("TTY %s\n",ttyname(fileno(f)));
else
printf("not a TTY\n");
}
int main(void){
print_tty("stdin",stdin);
print_tty("stdout",stdout);
print_tty("stderr",stderr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment