summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-12-24 02:17:47 -0800
committerJim Meyering <meyering@redhat.com>2011-12-24 15:05:28 +0100
commitd0be2a62a38726211cd94a06fd7e9aa23a88d07d (patch)
treec47290d1473ef6221e011d2386d775ed4cfc19cc
parentadfe8bb24cbdb0c0feaf69e573ba6c023921cd33 (diff)
downloadgrep-d0be2a62a38726211cd94a06fd7e9aa23a88d07d.tar.gz
don't ignore errors when reading a directory
grep no longer silently suppresses errors when reading a directory as if it were a text file. For example, "grep x ." now reports a read error on most systems; formerly, it ignored the error. Problem reported as an aside by Bob Proulx (Bug#10355). * NEWS: Document this. * src/main.c (grep, grepfile): Implement this. Simplify the code considerably. * src/system.h (is_EISDIR): Remove; no longer needed.
-rw-r--r--NEWS5
-rw-r--r--src/main.c41
-rw-r--r--src/system.h6
3 files changed, 11 insertions, 41 deletions
diff --git a/NEWS b/NEWS
index 32cb32ec..38241596 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,11 @@ GNU grep NEWS -*- outline -*-
** Bug fixes
+ grep no longer silently suppresses errors when reading a directory
+ as if it were a text file. For example, "grep x ." now reports a
+ read error on most systems; formerly, it ignored the error.
+ [bug introduced in grep-2.5]
+
The --include, --exclude, and --exclude-dir options now handle
command-line arguments more consistently. --include and --exclude
apply only to non-directories and --exclude-dir applies only to
diff --git a/src/main.c b/src/main.c
index 70197f42..1e1667ac 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1098,8 +1098,7 @@ grep (int fd, char const *file, struct stats *stats)
if (! fillbuf (save, stats))
{
- if (! is_EISDIR (errno, file))
- suppressible_error (filename, errno);
+ suppressible_error (filename, errno);
return 0;
}
@@ -1170,8 +1169,7 @@ grep (int fd, char const *file, struct stats *stats)
nlscan (beg);
if (! fillbuf (save, stats))
{
- if (! is_EISDIR (errno, file))
- suppressible_error (filename, errno);
+ suppressible_error (filename, errno);
goto finish_grep;
}
}
@@ -1252,37 +1250,10 @@ grepfile (char const *file, struct stats *stats)
if (desc < 0)
{
int e = errno;
-
- if (is_EISDIR (e, file) && directories == RECURSE_DIRECTORIES)
- {
- if (stat (file, &stats->stat) != 0)
- {
- error (0, errno, "%s", file);
- return 1;
- }
-
- return grepdir (file, stats);
- }
-
- if (!suppress_errors)
- {
- if (directories == SKIP_DIRECTORIES)
- switch (e)
- {
-#if defined EISDIR
- case EISDIR:
- return 1;
-#endif
- case EACCES:
- /* When skipping directories, don't worry about
- directories that can't be opened. */
- if (isdir (file))
- return 1;
- break;
- }
- }
-
- suppressible_error (file, e);
+ /* When skipping directories, don't worry about directories
+ that can't be opened. */
+ if (! (directories == SKIP_DIRECTORIES && isdir (file)))
+ suppressible_error (file, e);
return 1;
}
diff --git a/src/system.h b/src/system.h
index e7afc46d..db2fea3f 100644
--- a/src/system.h
+++ b/src/system.h
@@ -33,12 +33,6 @@
# define HAVE_DOS_FILE_CONTENTS 1
#endif
-#ifdef EISDIR
-# define is_EISDIR(e, f) ((e) == EISDIR)
-#else
-# define is_EISDIR(e, f) 0
-#endif
-
#include <stdlib.h>
#include <stddef.h>
#include <limits.h>