Make sure if errno is set it returns the correct value, also fixed a typo in a comment