blob: b4232aec2545b3c0d5c4b559dbcfcdc129323cb8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
static char *
storeline(FILE *in, int *end, int *len, int guess)
{
static char *line;
line = calloc(guess, sizeof(char));
int i = 0, buflen = guess;
char ch;
while ((ch = fgetc(in)) != EOF && ch != '\n') {
if (i == buflen - 1) {
buflen += guess;
line = realloc(line, buflen * sizeof(char));
}
line[i] = ch;
++i;
}
line[i] = '\0';
*len = i;
if (ch == EOF)
*end = 1;
return line;
}
|