stat file before attempting to open

A little refactoring