Question

I've been using scandir, and differentiating between directories and files using d_type:

int isdir(const struct dirent *entry)
{
return entry->d_name[0]!='.' && entry->d_type&4;
}

and

int isfile(const struct dirent *entry)
{
return entry->d_name[0]!='.' && entry->d_type&8;
}

It's abundantly clear that 0100b is a directory, and 1000b is a file, and after a bit of sleuthing it became obvious to me that 0010b represents a symbolic link. So you'd think (or at least, I did) that 0110b would represent a symlink directory, and that 1010b would be a symlink to a file, but that's not what I'm experiencing.

Instead, all symlinks are showing a d_type of 1010b be they regular file or directory. How can I differentiate a symlink file from a symlink directory?

Was it helpful?

Solution

There is no "symlink file" or "symlink directory". A symlink is its own type: it's the same kind of object no matter what it points to. Also, it need not even point to anything: a symlink can be broken. Look at the stat system call, and compare with lstat. stat reads through a symlink; lstat gets the properties of a symlink inode itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top