Commit c5b3cb3b by Rudolf

Error out in case directory is inputted or input is 0 size

parent b4cad620
Showing with 13 additions and 0 deletions
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include "print_helper.h" #include "print_helper.h"
...@@ -108,6 +109,18 @@ int main(int argc, char *argv[]) ...@@ -108,6 +109,18 @@ int main(int argc, char *argv[])
outfile = argv[2]; outfile = argv[2];
} }
struct stat in_stat;
stat(infile, &in_stat);
if (!S_ISREG(in_stat.st_mode)) {
fprintf(stderr, "Input is not a file\n");
return -1;
}
if (in_stat.st_size == 0) {
fprintf(stderr, "Input file is empty\n");
return -1;
}
FILE *input = fopen(infile, "r"); FILE *input = fopen(infile, "r");
if (!input) { if (!input) {
fprintf(stderr, "Failed to open input file\n"); fprintf(stderr, "Failed to open input file\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment