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); }