Checks for valid file before init

This commit is contained in:
Themaister 2010-05-29 15:21:30 +02:00
parent 0e50d35a0d
commit 77a1e1541c

12
ssnes.c
View File

@ -212,6 +212,14 @@ int main(int argc, char *argv[])
fprintf(stderr, "Usage: %s file\n", argv[0]); fprintf(stderr, "Usage: %s file\n", argv[0]);
exit(1); exit(1);
} }
FILE *file = fopen(argv[1], "rb");
if ( file == NULL )
{
fprintf(stderr, "Could not open file: \"%s\"\n", argv[1]);
exit(1);
}
char savefile_name[strlen(argv[1]+5)]; char savefile_name[strlen(argv[1]+5)];
strcpy(savefile_name, argv[1]); strcpy(savefile_name, argv[1]);
strcat(savefile_name, ".sav"); strcat(savefile_name, ".sav");
@ -226,10 +234,6 @@ int main(int argc, char *argv[])
snes_set_input_state(input_state); snes_set_input_state(input_state);
FILE *file = fopen(argv[1], "rb");
if ( file == NULL )
exit(1);
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
long length = ftell(file); long length = ftell(file);
rewind(file); rewind(file);