fix error with returning the wrong error code for opening a file