Turn my disgusting readdir macros into a reasonably clean function