Improved the error checking on calls to fopen().