From 7168d49e0d601e2dffd54128cd6f41082b55afbe Mon Sep 17 00:00:00 2001 From: gabor Date: Thu, 1 Dec 2011 13:53:33 +0000 Subject: [PATCH] MFC 228093 - Fix behavior of --null to match GNU grep MFC 228097 - Call warnx() instead of errx() if a directory is not readable when using a recursive search. This is the expected behavior instead of aborting. Approved by: re (kib) git-svn-id: svn://svn.freebsd.org/base/releng/9.0@228180 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/grep/util.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 785961b1..75ed1078 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -130,7 +130,9 @@ grep_tree(char **argv) case FTS_DNR: /* FALLTHROUGH */ case FTS_ERR: - errx(2, "%s: %s", p->fts_path, strerror(p->fts_errno)); + notfound = true; + if(!sflag) + warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); break; case FTS_D: /* FALLTHROUGH */ @@ -246,9 +248,9 @@ procfile(const char *fn) printf("%u\n", c); } if (lflag && !qflag && c != 0) - printf("%s\n", fn); + printf("%s%c", fn, nullflag ? 0 : '\n'); if (Lflag && !qflag && c == 0) - printf("%s\n", fn); + printf("%s%c", fn, nullflag ? 0 : '\n'); if (c && !cflag && !lflag && !Lflag && binbehave == BINFILE_BIN && f->binary && !qflag) printf(getstr(8), fn); @@ -440,13 +442,13 @@ printline(struct str *line, int sep, regmatch_t *matches, int m) int i, n = 0; if (!hflag) { - if (nullflag == 0) + if (!nullflag) { fputs(line->file, stdout); - else { + ++n; + } else { printf("%s", line->file); putchar(0); } - ++n; } if (nflag) { if (n > 0) -- 2.42.0