use agetline instead of agets

also use agetline where fgets with a static buffer was used previously.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma
2014-06-01 15:04:32 +02:00
committed by sin
parent eac0f658cf
commit fab4b384e7
9 changed files with 35 additions and 27 deletions

View File

@@ -50,7 +50,7 @@ cryptcheck(char *sumfile, int argc, char *argv[],
else if(!(cfp = fopen(sumfile, "r")))
eprintf("fopen %s:", sumfile);
while(afgets(&line, &bufsiz, cfp)) {
while(agetline(&line, &bufsiz, cfp) != -1) {
if(!(file = strstr(line, " "))) {
formatsucks++;
continue;

View File

@@ -10,10 +10,10 @@ void
getlines(FILE *fp, struct linebuf *b)
{
char *line = NULL, **nline;
size_t size = 0;
size_t linelen;
size_t size = 0, linelen;
ssize_t len;
while(afgets(&line, &size, fp)) {
while((len = agetline(&line, &size, fp)) != -1) {
if(++b->nlines > b->capacity) {
b->capacity += 512;
nline = realloc(b->lines, b->capacity * sizeof(*b->lines));
@@ -21,10 +21,10 @@ getlines(FILE *fp, struct linebuf *b)
eprintf("realloc:");
b->lines = nline;
}
if(!(b->lines[b->nlines-1] = malloc((linelen = strlen(line)+1))))
linelen = len + 1;
if(!(b->lines[b->nlines-1] = malloc(linelen)))
eprintf("malloc:");
memcpy(b->lines[b->nlines-1], line, linelen);
}
free(line);
}