Move in_named_pipe below is_symlink, in case opts.follow_symlinks is false. Fix whitespace.
Only stat() if d_type is DT_UNKNOWN. This drastically reduces the number of calls to stat() on most systems.