Change test order, check stat output

This commit is contained in:
Franck STAUFFER 2020-08-04 13:36:24 +02:00
parent 9a6cb3b779
commit b1050eb74b
Signed by: franck.stauffer
GPG Key ID: AAF5A94045CEC261
1 changed files with 9 additions and 6 deletions

View File

@ -5,9 +5,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#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;
}