Replace homemade getline(3) by actual getline(3)
This commit is contained in:
parent
bc188bd4f8
commit
94678ee678
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user