Distinguishing a pipe from a file in Unix
Use the fstat() function. However, you'll need to use the fileno() macro to get the file descriptor from file FILE struct.
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>FILE *fp = fopen(path, "r");int fd = fileno(fp);struct stat statbuf;fstat(fd, &statbuf);/* a decoding case statement would be good here */printf("%s is file type %08o\n", path, (statbuf.st_mode & 0777000);