Refactored multiple return paths to use unix-standard errno values as return values to provide more detailed error output.