really long lines

This commit is contained in:
Connor Lane Smith
2011-05-25 20:40:47 +01:00
parent 47308190b3
commit d6a9e35d0b
5 changed files with 52 additions and 14 deletions

24
util/afgets.c Normal file
View File

@@ -0,0 +1,24 @@
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../text.h"
#include "../util.h"
char *
afgets(char **p, size_t *size, FILE *fp)
{
char buf[BUFSIZ];
size_t n, len = 0;
while(fgets(buf, sizeof buf, fp)) {
len += (n = strlen(buf));
if(len+1 > *size && !(*p = realloc(*p, len+1)))
eprintf("realloc:");
strcpy(&(*p)[len-n], buf);
if(buf[n-1] == '\n' || feof(fp))
break;
}
return *p;
}