diff options
-rw-r--r-- | findutils/grep.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index f72175afb..fc6de4b69 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -639,11 +639,28 @@ static void load_regexes_from_file(llist_t *fopt) | |||
639 | } | 639 | } |
640 | 640 | ||
641 | static int FAST_FUNC file_action_grep(const char *filename, | 641 | static int FAST_FUNC file_action_grep(const char *filename, |
642 | struct stat *statbuf UNUSED_PARAM, | 642 | struct stat *statbuf, |
643 | void* matched, | 643 | void* matched, |
644 | int depth UNUSED_PARAM) | 644 | int depth UNUSED_PARAM) |
645 | { | 645 | { |
646 | FILE *file = fopen_for_read(filename); | 646 | FILE *file; |
647 | |||
648 | /* If we are given a link to a directory, we should bail out now, rather | ||
649 | * than trying to open the "file" and hoping getline gives us nothing, | ||
650 | * since that is not portable across operating systems (FreeBSD for | ||
651 | * example will return the raw directory contents). */ | ||
652 | if (S_ISLNK(statbuf->st_mode)) { | ||
653 | struct stat sb; | ||
654 | if (stat(filename, &sb) != 0) { | ||
655 | if (!SUPPRESS_ERR_MSGS) | ||
656 | bb_simple_perror_msg(filename); | ||
657 | return 0; | ||
658 | } | ||
659 | if (S_ISDIR(sb.st_mode)) | ||
660 | return 1; | ||
661 | } | ||
662 | |||
663 | file = fopen_for_read(filename); | ||
647 | if (file == NULL) { | 664 | if (file == NULL) { |
648 | if (!SUPPRESS_ERR_MSGS) | 665 | if (!SUPPRESS_ERR_MSGS) |
649 | bb_simple_perror_msg(filename); | 666 | bb_simple_perror_msg(filename); |