fix error handling conditions for fopen

Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>