Use stat() instead of dirent.d_type

Illumos does not have the d_type member in struct dirent.  To be more
portable, use stat() instead.

Fixes #116.