Is stat() being used to obtain sb? It will dereference the link, so ISDIR may be true, even if filename is in fact a symlink. lstat() stats the link.