I am printing the result of S_ISDIR(info->st_mode)
and S_ISREG(info->st_mode)
over a directory that contains dynamic libraries with .so
extension and the result is quite surprising, S_ISREG
returns 0
while S_ISDIR
returns 1.
I am a bit confused...
The code:
DIR *dir;
if ((dir = opendir (dirname)) != NULL) {
struct dirent *ent;
while ((ent = readdir (dir)) != NULL) {
struct stat info;
stat(ent->d_name, &info);
printf("file: %s, S_ISREG: %d, S_ISDIR: %d", ent->d_name, S_ISREG(info.st_mode), S_ISDIR(info.st_mode));
}
}
closedir(dir);
The output looks like:
file: ., S_ISREG: 0, S_ISDIR: 1
file: zyva.so, S_ISREG: 0, S_ISDIR: 1
file: .gitignore, S_ISREG: 1, S_ISDIR: 0
file: .., S_ISREG: 0, S_ISDIR: 1
file: plugin-app, S_ISREG: 0, S_ISDIR: 1
file: chat.so, S_ISREG: 0, S_ISDIR: 1
plugin-app is also an executable so it's also a regular file...