Add check for regular file
This commit is contained in:
parent
d26230c766
commit
9a6cb3b779
18
src/main.c
18
src/main.c
@ -7,6 +7,7 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user