Replace use of d_type member of struct dirent with stat()

Illumos does not have the d_type member in struct dirent. To be more
portable,

this web page:

http://stackoverflow.com/questions/2197918/cross-platform-way-of-testing-whether-a-file-is-a-directory

recommends converting code like this:

    if (de->d_type == DT_DIR)
    {
       return 0;
    }

to this:

    struct stat s; /*include sys/stat.h if necessary */
    ..
    ..
    stat(de->d_name, &s);
    if (s.st_mode & S_IFDIR)
    {
        return 0;
    }
The meaning of expected_type has changed.  Please update the documentation on the input parameter above.  (Can't add the comment to the untouched line; thanks GitHub...)