No need to free the buffer for every call to getline()

It will realloc as necessary if the new line size exceeds the
capacity of the allocated buffer.
This commit is contained in:
sin 2015-02-09 14:10:24 +00:00
parent 2a83c2c8be
commit 080a1ee833

7
tail.c
View File

@ -101,13 +101,12 @@ main(int argc, char *argv[])
tail(fp, argv[0], n); tail(fp, argv[0], n);
if (fflag && argc == 1) { if (fflag && argc == 1) {
for(;; tmp = NULL, tmpsize = 0) { tmp = NULL;
tmpsize = 0;
for(;;) {
while (getline(&tmp, &tmpsize, fp) != -1) { while (getline(&tmp, &tmpsize, fp) != -1) {
fputs(tmp, stdout); fputs(tmp, stdout);
fflush(stdout); fflush(stdout);
free(tmp);
tmp = NULL;
tmpsize = 0;
} }
if (ferror(fp)) if (ferror(fp))
eprintf("readline '%s':", argv[0]); eprintf("readline '%s':", argv[0]);