From b1050eb74b9002774b2a31b35e8821213a8bd8c7 Mon Sep 17 00:00:00 2001 From: Franck STAUFFER Date: Tue, 4 Aug 2020 13:36:24 +0200 Subject: [PATCH] Change test order, check stat output --- src/main.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 4e49c81..5131292 100644 --- a/src/main.c +++ b/src/main.c @@ -5,9 +5,9 @@ #include #include #include +#include #include #include -#include #define X (op & 0x0F00) >> 8 #define Y (op & 0x00F0) >> 4 @@ -588,7 +588,10 @@ uint_fast8_t is_file(const char* path) { struct stat s; - stat(path, &s); + if (stat(path, &s)) { + fputs("ERROR: Failed to see stats about provided file\n", stderr); + exit(1); + } return S_ISREG(s.st_mode); } @@ -617,13 +620,13 @@ main(int argc, char** argv) return 1; } - if (!is_file(argv[1])) { - fputs("ERROR: Provided file is not a regular file\n", stderr); + if (access(argv[1], R_OK)) { + fputs("ERROR: No read permission to provided file\n", stderr); return 1; } - if (access(argv[1], R_OK)) { - fputs("ERROR: No read permission to provided file\n", stderr); + if (!is_file(argv[1])) { + fputs("ERROR: Provided file is not a regular file\n", stderr); return 1; }