diff --git a/src/main.c b/src/main.c index 01b9edf..4e49c81 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #define X (op & 0x0F00) >> 8 #define Y (op & 0x00F0) >> 4 @@ -583,6 +584,14 @@ op_handler(void) } } +uint_fast8_t +is_file(const char* path) +{ + struct stat s; + stat(path, &s); + return S_ISREG(s.st_mode); +} + void timers() { @@ -604,12 +613,17 @@ main(int argc, char** argv) } if (access(argv[1], F_OK)) { - fputs("ERROR: Provided ROM file does not exist\n", stderr); + fputs("ERROR: Provided file does not exist\n", stderr); + return 1; + } + + if (!is_file(argv[1])) { + fputs("ERROR: Provided file is not a regular file\n", stderr); return 1; } if (access(argv[1], R_OK)) { - fputs("ERROR: No read permission to provided ROM file\n", stderr); + fputs("ERROR: No read permission to provided file\n", stderr); return 1; }