[hackers] [sbase] grep: Fix exit status with -F when last line doesn't match || Michael Forney

From: <git_AT_suckless.org>
Date: Sat, 14 May 2016 13:58:43 +0200 (CEST)

commit e6b3af07cf5488dde5da9bc7f15353c06216e51c
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Fri May 13 23:34:51 2016 -0700
Commit: sin <sin_AT_2f30.org>
CommitDate: Sat May 14 12:58:38 2016 +0100

    grep: Fix exit status with -F when last line doesn't match
    
    Test case:
    
    if printf '%s\n' foo bar | ./grep -F foo >/dev/null ; then
            echo pass
    else
            echo fail
    fi

diff --git a/grep.c b/grep.c
index ae23967..fb911ff 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -107,7 +107,7 @@ grep(FILE *fp, const char *str)
         ssize_t len = 0;
         long c = 0, n;
         struct pattern *pnode;
- int match = NoMatch;
+ int match, result = NoMatch;
 
         for (n = 1; (len = getline(&buf, &size, fp)) > 0; n++) {
                 /* Remove the trailing newline if one is present. */
_AT_@ -149,7 +149,7 @@ grep(FILE *fp, const char *str)
                                 puts(buf);
                                 break;
                         }
- match = Match;
+ result = Match;
                         break;
                 }
         }
_AT_@ -158,9 +158,9 @@ grep(FILE *fp, const char *str)
 end:
         if (ferror(fp)) {
                 weprintf("%s: read error:", str);
- match = Error;
+ result = Error;
         }
- return match;
+ return result;
 }
 
 static void
Received on Sat May 14 2016 - 13:58:43 CEST

This archive was generated by hypermail 2.3.0 : Sat May 14 2016 - 14:00:24 CEST