Lines 111-116
grep_tree(char **argv)
Link Here
|
111 |
FTSENT *p; |
111 |
FTSENT *p; |
112 |
int c, fts_flags; |
112 |
int c, fts_flags; |
113 |
bool ok; |
113 |
bool ok; |
|
|
114 |
char **tdir = NULL, *pwd = NULL; |
114 |
|
115 |
|
115 |
c = fts_flags = 0; |
116 |
c = fts_flags = 0; |
116 |
|
117 |
|
Lines 128-134
grep_tree(char **argv)
Link Here
|
128 |
|
129 |
|
129 |
fts_flags |= FTS_NOSTAT | FTS_NOCHDIR; |
130 |
fts_flags |= FTS_NOSTAT | FTS_NOCHDIR; |
130 |
|
131 |
|
131 |
if (!(fts = fts_open(argv, fts_flags, NULL))) |
132 |
if (argv[0] == NULL) { |
|
|
133 |
tdir = grep_calloc(2, sizeof(char *)); |
134 |
if ((pwd = getcwd(NULL, 0)) == NULL) |
135 |
err(2, "getcwd"); |
136 |
tdir[0] = pwd; |
137 |
} |
138 |
|
139 |
if (!(fts = fts_open((tdir != NULL ? tdir : argv), fts_flags, NULL))) |
132 |
err(2, "fts_open"); |
140 |
err(2, "fts_open"); |
133 |
while ((p = fts_read(fts)) != NULL) { |
141 |
while ((p = fts_read(fts)) != NULL) { |
134 |
switch (p->fts_info) { |
142 |
switch (p->fts_info) { |
Lines 165-170
grep_tree(char **argv)
Link Here
|
165 |
} |
173 |
} |
166 |
|
174 |
|
167 |
fts_close(fts); |
175 |
fts_close(fts); |
|
|
176 |
|
177 |
if(pwd != NULL) |
178 |
free(pwd); |
179 |
|
180 |
if(tdir != NULL) |
181 |
free(tdir); |
182 |
|
168 |
return (c); |
183 |
return (c); |
169 |
} |
184 |
} |
170 |
|
185 |
|