PERFORCE change 144094 for review
Gabor Kovesdan
gabor at FreeBSD.org
Wed Jun 25 13:19:42 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=144094
Change 144094 by gabor at gabor_server on 2008/06/25 13:18:43
- Show a warning on recursive directories
- Better check for -d and -D behaviour
Obtained from: NetBSD Project
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#49 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#41 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#49 (text+ko) ====
@@ -343,7 +343,6 @@
{
int c, lastc, prevoptind, newarg, i;
char *ep;
- struct stat *finfo = 0;
unsigned long long l;
setlocale(LC_ALL, "");
@@ -611,22 +610,7 @@
if (dirbehave == DIR_RECURSE)
c = grep_tree(argv);
else
- for (c = 0; argc--; ++argv) {
- if (devbehave == DEV_SKIP) {
- finfo = grep_malloc(sizeof(struct stat));
- if (stat(*argv, finfo) == -1)
- err(2, NULL);
- if (S_ISBLK(finfo->st_mode) ||
- S_ISCHR(finfo->st_mode) ||
- S_ISFIFO(finfo->st_mode) ||
- S_ISSOCK(finfo->st_mode)) {
- free(finfo);
- continue;
- } else
- free(finfo);
- }
- c+= procfile(*argv);
- }
+ c+= procfile(*argv);
#ifndef WITHOUT_NLS
catclose(catalog);
==== //depot/projects/soc2008/gabor_textproc/grep/util.c#41 (text+ko) ====
@@ -85,28 +85,13 @@
errx(2, "%s: %s", p->fts_path, strerror(p->fts_errno));
break;
case FTS_DP:
+ case FTS_D:
+ break;
+ case FTS_DC:
+ warnx("warning: %s: recursive directory loop",
+ p->fts_path);
break;
default:
- if ((devbehave == DEV_SKIP) || (dirbehave == DIR_RECURSE) || (dirbehave == DIR_SKIP)) {
- struct stat *finfo;
-
- finfo = grep_malloc(sizeof(struct stat));
- if (stat(p->fts_path, finfo) == -1)
- err(2, NULL);
-
- if ((devbehave == DEV_SKIP) && (S_ISBLK(finfo->st_mode) ||
- S_ISCHR(finfo->st_mode) ||
- S_ISFIFO(finfo->st_mode) ||
- S_ISSOCK(finfo->st_mode))) {
- free(finfo);
- break;
- }
- if (((dirbehave == DIR_RECURSE) || (dirbehave == DIR_SKIP)) && S_ISDIR(finfo->st_mode)) {
- free(finfo);
- break;
- }
- free(finfo);
- }
c += procfile(p->fts_path);
break;
}
@@ -122,6 +107,8 @@
{
struct str ln;
struct file *f;
+ struct stat sb;
+ mode_t s;
int c, t, nottext;
if (mflag && (mcount <= 0))
@@ -134,6 +121,16 @@
fn = getstr(1);
f = grep_stdin_open();
} else {
+ if (stat(fn, &sb))
+ err(2, NULL);
+ else {
+ s = sb.st_mode & S_IFMT;
+ if (s == S_IFDIR && dirbehave == DIR_SKIP)
+ return (0);
+ if ((s == S_IFIFO || s == S_IFCHR || s == S_IFBLK
+ || s == S_IFSOCK) && devbehave == DEV_SKIP)
+ return (0);
+ }
f = grep_open(fn);
}
if (f == NULL) {
More information about the p4-projects
mailing list