37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
int ch;
char *tmp = malloc(512);
size_t s = 512;
size_t r = 0;
while ((ch = fgetc(h)) != EOF) {
if (r == s) {
//grow tmp
char *ttmp = realloc(tmp, (13*s)/8);
if (ttmp) {
tmp = ttmp;
s = (13*s)/8;
} else {
free(tmp);
return 0;
}
|
|
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
int ch;
char *tmp = malloc(512);
size_t s = 512;
size_t r = 0;
while ((ch = fgetc(h)) != EOF) {
if (r == s) {
//grow tmp
char *ttmp = realloc(tmp, (13*s)/8); // 13/8 is within 0.5% of the golden ratio
if (ttmp) {
tmp = ttmp;
s = (13*s)/8;
} else {
free(tmp);
return 0;
}
|