sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 2b39f2067530db39d4da70b8fde71a6923269136
parent 228e8c4a0b90abdee9ffc5825108e944b3d06e90
Author: sin <sin@2f30.org>
Date:   Fri, 21 Nov 2014 11:43:53 +0000

Respect exit status in grep(1)

Diffstat:
Mgrep.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/grep.c b/grep.c @@ -160,16 +160,22 @@ addpattern(const char *pattern) pattern = "."; if (!Fflag && xflag) { - tmp = emalloc(strlen(pattern) + 3); + tmp = malloc(strlen(pattern) + 3); + if (!tmp) + enprintf(Error, "malloc:"); snprintf(tmp, strlen(pattern) + 3, "%s%s%s", pattern[0] == '^' ? "" : "^", pattern, pattern[strlen(pattern) - 1] == '$' ? "" : "$"); } else { - tmp = estrdup(pattern); + tmp = strdup(pattern); + if (!tmp) + enprintf(Error, "strdup:"); } - pnode = emalloc(sizeof(*pnode)); + pnode = malloc(sizeof(*pnode)); + if (!pnode) + enprintf(Error, "malloc:"); pnode->pattern = tmp; SLIST_INSERT_HEAD(&phead, pnode, entry); } @@ -186,6 +192,8 @@ addpatternfile(FILE *fp) addpattern(buf); } free(buf); + if (ferror(fp)) + enprintf(Error, "read error:"); } static int