Compatibility fix for new opendir code in newlib, plus better error reporting when opening a directory for writing