Move fgetline out into misc.c.

I'm about to want to use it outside the GTK front end.
This commit is contained in:
Simon Tatham
2018-04-22 13:58:27 +01:00
parent 12cb1adc88
commit b7034aeb51
3 changed files with 20 additions and 19 deletions

19
misc.c
View File

@ -169,6 +169,25 @@ unsigned char *hex2bin(const char *in, int outlen)
return ret;
}
char *fgetline(FILE *fp)
{
char *ret = snewn(512, char);
int size = 512, len = 0;
while (fgets(ret + len, size - len, fp)) {
len += strlen(ret + len);
if (ret[len-1] == '\n')
break; /* got a newline, we're done */
size = len + 512;
ret = sresize(ret, size, char);
}
if (len == 0) { /* first fgets returned NULL */
sfree(ret);
return NULL;
}
ret[len] = '\0';
return ret;
}
void game_mkhighlight_specific(frontend *fe, float *ret,
int background, int highlight, int lowlight)
{