Add check for regular file

This commit is contained in:
Franck STAUFFER 2020-08-04 12:35:30 +02:00
parent d26230c766
commit 9a6cb3b779
Signed by: franck.stauffer
GPG Key ID: AAF5A94045CEC261
1 changed files with 16 additions and 2 deletions

View File

@ -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;
}