Respect exit status in grep(1)

This commit is contained in:
sin 2014-11-21 11:43:53 +00:00
parent 228e8c4a0b
commit 2b39f20675
1 changed files with 11 additions and 3 deletions

14
grep.c
View File

@ -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