Answers
#include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main() { struct stat st; fstat(STDOUT_FILENO, &st); if(S_ISCHR(st.st_mode)) fprintf(stderr, "terminal\n"); else if(S_ISREG(st.st_mode)) fprintf(stderr, "regular file\n"); else { //what ever } return 0; }
撸炮大魔王
answered 10 years, 5 months ago