From 41a0806297ad6e31c33a9d25b0138a5ae90546d8 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sun, 16 Jun 2019 11:47:50 +0300 Subject: Fix check for valid file, add -F to help --- fcomp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'fcomp.c') diff --git a/fcomp.c b/fcomp.c index bff6823..65f5812 100644 --- a/fcomp.c +++ b/fcomp.c @@ -144,6 +144,8 @@ static void print_help(char *argv0) "Same"); fprintf(stderr, "%8s %4s %15s %50s\n", "-f", "[..]", "file", "Select the input file to use"); + fprintf(stderr, "%8s %4s %15s %50s\n", "-F", "[..]", "filestream", + "Input can be provided as a string"); fprintf(stderr, "%8s %4s %15s %50s\n", "stdin", "[..]", "", "Input can come from rediretion as well as files"); fprintf(stderr, "%8s %4s %15s %50s\n", "-z", "", "fuzzy", @@ -688,9 +690,11 @@ static int set_input(FILE **f) if (!cfg.file || strcmp(cfg.file, "") == 0) return -1; *f = fmemopen(cfg.file, strlen(cfg.file), "r"); - } else { + if (!*f) return -1; + } + else { *f = fopen(cfg.file, "r"); - if (!f) { + if (!*f) { fprintf(stderr, "Couldn't open %s\n", cfg.file); return -1; } -- cgit v1.2.3