diff options
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 3acfa9197..5f4224203 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -562,20 +562,20 @@ static char *add_grep_list_data(char *pattern) | |||
562 | 562 | ||
563 | static void load_regexes_from_file(llist_t *fopt) | 563 | static void load_regexes_from_file(llist_t *fopt) |
564 | { | 564 | { |
565 | char *line; | ||
566 | FILE *f; | ||
567 | |||
568 | while (fopt) { | 565 | while (fopt) { |
566 | char *line; | ||
567 | FILE *fp; | ||
569 | llist_t *cur = fopt; | 568 | llist_t *cur = fopt; |
570 | char *ffile = cur->data; | 569 | char *ffile = cur->data; |
571 | 570 | ||
572 | fopt = cur->link; | 571 | fopt = cur->link; |
573 | free(cur); | 572 | free(cur); |
574 | f = xfopen_stdin(ffile); | 573 | fp = xfopen_stdin(ffile); |
575 | while ((line = xmalloc_fgetline(f)) != NULL) { | 574 | while ((line = xmalloc_fgetline(fp)) != NULL) { |
576 | llist_add_to(&pattern_head, | 575 | llist_add_to(&pattern_head, |
577 | new_grep_list_data(line, ALLOCATED)); | 576 | new_grep_list_data(line, ALLOCATED)); |
578 | } | 577 | } |
578 | fclose_if_not_stdin(fp); | ||
579 | } | 579 | } |
580 | } | 580 | } |
581 | 581 | ||
@@ -659,15 +659,19 @@ int grep_main(int argc UNUSED_PARAM, char **argv) | |||
659 | #endif | 659 | #endif |
660 | invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ | 660 | invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ |
661 | 661 | ||
662 | if (pattern_head != NULL) { | 662 | { /* convert char **argv to grep_list_data_t */ |
663 | /* convert char **argv to grep_list_data_t */ | ||
664 | llist_t *cur; | 663 | llist_t *cur; |
665 | |||
666 | for (cur = pattern_head; cur; cur = cur->link) | 664 | for (cur = pattern_head; cur; cur = cur->link) |
667 | cur->data = new_grep_list_data(cur->data, 0); | 665 | cur->data = new_grep_list_data(cur->data, 0); |
668 | } | 666 | } |
669 | if (option_mask32 & OPT_f) | 667 | if (option_mask32 & OPT_f) { |
670 | load_regexes_from_file(fopt); | 668 | load_regexes_from_file(fopt); |
669 | if (!pattern_head) { /* -f EMPTY_FILE? */ | ||
670 | /* GNU grep treats it as "nothing matches" */ | ||
671 | llist_add_to(&pattern_head, new_grep_list_data((char*) "", 0)); | ||
672 | invert_search ^= 1; | ||
673 | } | ||
674 | } | ||
671 | 675 | ||
672 | if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f') | 676 | if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f') |
673 | option_mask32 |= OPT_F; | 677 | option_mask32 |= OPT_F; |