On Dec 27, 2012, at 11:00 AM, Jiri B <[email protected]> wrote:

> Only ports@ list accepts attachment, put it inline.


Sorry about that. Here is the patch:

Index: grep.c
===================================================================
RCS file: /cvs/src/usr.bin/grep/grep.c,v
retrieving revision 1.44
diff -u -r1.44 grep.c
--- grep.c      8 Jul 2011 01:20:24 -0000       1.44
+++ grep.c      27 Dec 2012 18:28:48 -0000
@@ -84,6 +84,8 @@
 
 int binbehave = BIN_FILE_BIN;
 
+int openerr;
+
 enum {
        BIN_OPT = CHAR_MAX + 1,
        HELP_OPT,
@@ -491,11 +493,15 @@
        if (argc == 0)
                exit(!procfile(NULL));
 
+       openerr = 0;
        if (Rflag)
                c = grep_tree(argv);
        else
                for (c = 0; argc--; ++argv)
                        c += procfile(*argv);
 
-       exit(!c);
+       if (openerr)
+               exit(2);
+       else
+               exit(!c);
 }
Index: grep.h
===================================================================
RCS file: /cvs/src/usr.bin/grep/grep.h,v
retrieving revision 1.17
diff -u -r1.17 grep.h
--- grep.h      8 Jul 2011 01:20:24 -0000       1.17
+++ grep.h      27 Dec 2012 18:28:48 -0000
@@ -74,6 +74,9 @@
 extern fastgrep_t *fg_pattern;
 extern regex_t *r_pattern;
 
+/* Flag indicating open file error */
+extern int openerr;
+
 /* For regex errors  */
 #define RE_ERROR_BUF 512
 extern char     re_error[RE_ERROR_BUF + 1];    /* Seems big enough */
Index: util.c
===================================================================
RCS file: /cvs/src/usr.bin/grep/util.c,v
retrieving revision 1.42
diff -u -r1.42 util.c
--- util.c      17 Jul 2011 19:39:21 -0000      1.42
+++ util.c      27 Dec 2012 18:28:48 -0000
@@ -103,6 +103,7 @@
        if (f == NULL) {
                if (!sflag)
                        warn("%s", fn);
+               openerr = 1;
                return 0;
        }

Reply via email to