how to read the return value of S_ISDIR macro.
It works fine when used in if loop, but how to print the returned value.
Thanks
bishweshwar
how to read the return value of S_ISDIR macro.
It works fine when used in if loop, but how to print the returned value.
Thanks
bishweshwar
S_ISDIR is simply a macro which checks the mode of a file to see whether the file is a directory. If so it returns true. Have a look in stat.h for more information.
struct stat buf;
......
if (S_ISDIR(buf->st_mode)) printf ("DIRECTORY ");
The return value of S_ISDIR will be the numerical representation of either TRUE or FALSE.
The S_ISDIR macro returns an integer. If the file is a directory the S_ISDIR macro returns non-zero and to print that value use it as an expression inside a printf statement.
printf("return value of S_ISDIR is %i\n", S_ISDIR(mode));