diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-12-03 09:14:38 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-12-03 09:14:38 +0000 |
commit | 6a1b27f1ba1d870dd24f1d2c98893b83442e504d (patch) | |
tree | bcddafd4f747e8867ea4b710d1b61cdfd93c6735 /usr.bin/grep/util.c | |
parent | 836f76b760c83baef9c6aaf7b81d83c9829f89bf (diff) |
With -R and an implicit ".", don't prepend file paths with "./"
Looks nicer and matches the output of GNU grep.
ok millert@ deraadt@ visa@ miod@
Diffstat (limited to 'usr.bin/grep/util.c')
-rw-r--r-- | usr.bin/grep/util.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index b683e8510b7..db605e99cee 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.61 2019/10/07 17:47:32 tedu Exp $ */ +/* $OpenBSD: util.c,v 1.62 2019/12/03 09:14:37 jca Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -61,6 +61,12 @@ grep_tree(char **argv) FTS *fts; FTSENT *p; int c, fts_flags; + char *dot_argv[] = { ".", NULL }; + char *path; + + /* default to . if no path given */ + if (argv[0] == NULL) + argv = dot_argv; c = 0; @@ -81,7 +87,11 @@ grep_tree(char **argv) case FTS_DP: break; default: - c += procfile(p->fts_path); + path = p->fts_path; + /* skip "./" if implied */ + if (argv == dot_argv && p->fts_pathlen >= 2) + path += 2; + c += procfile(path); break; } } |