Rework check around fopen() to be more idiomatic