[RDY] Fix: Writing in possible invalid buffer in mch_dirname().

uv_cwd() returns with error -EINVAL, in case no valid
buffer is used. Do not try to copy an error message into the buffer.

For all other errors copy only the first len characters of the error
message into the buffer.