Change test order, check stat output
This commit is contained in:
parent
9a6cb3b779
commit
b1050eb74b
15
src/main.c
15
src/main.c
@ -5,9 +5,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#define X (op & 0x0F00) >> 8
|
#define X (op & 0x0F00) >> 8
|
||||||
#define Y (op & 0x00F0) >> 4
|
#define Y (op & 0x00F0) >> 4
|
||||||
@ -588,7 +588,10 @@ uint_fast8_t
|
|||||||
is_file(const char* path)
|
is_file(const char* path)
|
||||||
{
|
{
|
||||||
struct stat s;
|
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);
|
return S_ISREG(s.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,13 +620,13 @@ main(int argc, char** argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_file(argv[1])) {
|
if (access(argv[1], R_OK)) {
|
||||||
fputs("ERROR: Provided file is not a regular file\n", stderr);
|
fputs("ERROR: No read permission to provided file\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(argv[1], R_OK)) {
|
if (!is_file(argv[1])) {
|
||||||
fputs("ERROR: No read permission to provided file\n", stderr);
|
fputs("ERROR: Provided file is not a regular file\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user