blob: ddaeca25604c7d17379ae5594dbce626b20a84ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
bufsize = 0x20,
};
static char *
getall(FILE *in)
{
char buf[bufsize];
static char *contents = NULL;
int len = 0, read;
while ((read = fread(buf, 1, bufsize, in)) > 0) {
len += read;
contents = realloc(contents, len);
memmove(&contents[len-read], buf, read);
}
contents = realloc(contents, ++len);
contents[len-1] = '\0';
return contents;
}
|