Log Message: Always include sys/types.h, it is needed on !NetBSD as well. Use dirent.h instead of sys/dir.h, the former is POSIX and the latter gives a warning on DragonFly, which breaks -Werror. Use NAME_MAX if available, fall back to MAXNAMLEN otherwise.