fix TOCTOU and simplify output directory creation
Fix compilation under LLVM2.9. SmallString in this old version does
not have the equals() method.