Check for ENOENT/ENOTDIR in chdir().
Note that the problem this solves, can still re-appear if the directory is removed while the CWD is pointed to it. The proper fix for that is to make relibc always use openat (and not have to do more canonicalization than .
and ..
).