i have a requirement where i need to check a given directory exists or not.
i am doing like this
structure stat buf;
stat(dir_path,buf);
if( S_ISDIR(buf.st_mode) )
cout << " its a directory " << endl;
else
cout << " its not a directory " << endl;
this procedure is not working sometimes. The output is not consistent for me.
Is it like, i should not perform S_ISDIR() when the stat() call fails ?
because what random behavior i am seeing here is..
stat() for the directory path fails and then i am trying S_ISDIR(buf.st_mode)
so, now this S_ISDIR() is not behaving correctly sometimes. why is this happening like this ? any idea ?