you can use fstat on the file descriptor returned by fopen.
Edit:
Here's and example program:
#include <sys/stat.h>
#include <stdio.h>
void printISDir( FILE* fp, char const * name ) {
int fdes = fileno(fp) ;
struct stat fileInfo ;
fstat(fdes, &fileInfo ) ;
if ( S_ISDIR(fileInfo.st_mode ) ) {
printf("%s: I'm a dir!\n", name ) ;
} else {
printf("%s: I'm a file!\n", name ) ;
}
}
int main( int argc, char** argv ) {
char const * directoryName = "/etc" ;
char const * fileName = "/etc/hosts" ;
FILE* dirFp = fopen(directoryName, "r") ;
FILE* fileFp = fopen(fileName, "r") ;
printISDir( dirFp, directoryName ) ;
printISDir( fileFp, fileName ) ;
fclose(dirFp) ;
fclose(fileFp) ;
return 0 ;
}