summaryrefslogtreecommitdiff
path: root/usr.bin/grep/util.c
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2019-12-03 09:14:38 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2019-12-03 09:14:38 +0000
commit6a1b27f1ba1d870dd24f1d2c98893b83442e504d (patch)
treebcddafd4f747e8867ea4b710d1b61cdfd93c6735 /usr.bin/grep/util.c
parent836f76b760c83baef9c6aaf7b81d83c9829f89bf (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.c14
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;
}
}