Rename withlibmagic to libmagic
Handle all IO errors from closeFd