diff options
author | Martin Tournoij <martin@arp242.net> | 2024-04-19 21:11:30 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2024-04-19 21:52:21 +0000 |
commit | 9744821765fccd6c9b44d47804b6913cdf616d4e (patch) | |
tree | a9ccbc970dc7f2a2055ffa896920d842e56707c7 /usr.bin/diff/diff.c | |
parent | b05785953e555e3dd13a162a8854076212026ca5 (diff) |
Diffstat (limited to 'usr.bin/diff/diff.c')
-rw-r--r-- | usr.bin/diff/diff.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 15ebbca28bd7..67aab0de91b5 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -517,20 +517,23 @@ static void read_excludes_file(char *file) { FILE *fp; - char *buf, *pattern; - size_t len; + char *pattern = NULL; + size_t blen = 0; + ssize_t len; if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) err(2, "%s", file); - while ((buf = fgetln(fp, &len)) != NULL) { - if (buf[len - 1] == '\n') - len--; - if ((pattern = strndup(buf, len)) == NULL) - err(2, "xstrndup"); + while ((len = getline(&pattern, &blen, fp)) >= 0) { + if ((len > 0) && (pattern[len - 1] == '\n')) + pattern[len - 1] = '\0'; push_excludes(pattern); + /* we allocate a new string per line */ + pattern = NULL; + blen = 0; } + free(pattern); if (strcmp(file, "-") != 0) fclose(fp); } |