Set errno in the correct way.