From fa97dd2a762612236336a1e9c282272fe27054aa Mon Sep 17 00:00:00 2001 From: bapt Date: Tue, 17 Dec 2019 11:03:32 +0000 Subject: [PATCH] Replace homemade getline(3) by actual getline(3) --- usr.bin/diff3/diff3.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index c475c3d65b07..03cd24283a13 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -257,28 +257,16 @@ getchange(FILE *b) static char * get_line(FILE *b, size_t *n) { - char *cp; - size_t len; - static char *buf; - static size_t bufsize; + ssize_t len; + static char *buf = NULL; + static size_t bufsize = 0; - if ((cp = fgetln(b, &len)) == NULL) + if ((len = getline(&buf, &bufsize, b)) < 0) return (NULL); - if (cp[len - 1] != '\n') - len++; - if (len + 1 > bufsize) { - do { - bufsize += 1024; - } while (len + 1 > bufsize); - if ((buf = realloc(buf, bufsize)) == NULL) - err(EXIT_FAILURE, NULL); - } - memcpy(buf, cp, len - 1); - buf[len - 1] = '\n'; - buf[len] = '\0'; if (n != NULL) *n = len; + return (buf); }