Return errno

In case of error, return the correct errno value or return the
latest errno value set.