include cleanups: remove unused headers and add feature test macros
optimize opendir using O_CLOEXEC
avoid fd leak if opendir is cancelled when calloc has failed
initial check-in, version 0.5.0