Conditionally include dirent.h and dlfcn.h

If you do not have a filesystem or do not support dav or
dynamic loading, the corresponding header files need not
be included (some environments might not have them).