by this
Why does fopen("any_path_name",'r') not give NULL as return?
i get to know that in linux directories and files are considered to b
man 2 stat
:
NAME
fstat, fstat64, lstat, lstat64, stat, stat64 -- get file status
...
struct stat {
dev_t st_dev; /* ID of device containing file */
mode_t st_mode; /* Mode of file (see below) */
...
The status information word st_mode has the following bits:
...
#define S_IFDIR 0040000 /* directory */
You can use S_ISDIR macro .
thanks zed_0xff and lgor Oks
this things can be check by this sample code
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
struct stat statbuf;
FILE *fb = fopen("/home/jeegar/","r");
if(fb==NULL)
printf("its null\n");
else
printf("not null\n");
stat("/home/jeegar/", &statbuf);
if(S_ISDIR(statbuf.st_mode))
printf("directory\n");
else
printf("file\n");
return 0;
}
output is
its null
directory