diff options
| author | Simon Tatham <anakin@pobox.com> | 2018-04-22 13:58:27 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2018-04-22 16:35:50 +0100 |
| commit | b7034aeb51a99336fca2e15837c8337481964f6d (patch) | |
| tree | f1e4fb0a418bec69e36ac6ab084467f338235f07 /misc.c | |
| parent | 12cb1adc886078d715abbc04e80912703340f496 (diff) | |
| download | puzzles-b7034aeb51a99336fca2e15837c8337481964f6d.zip puzzles-b7034aeb51a99336fca2e15837c8337481964f6d.tar.gz puzzles-b7034aeb51a99336fca2e15837c8337481964f6d.tar.bz2 puzzles-b7034aeb51a99336fca2e15837c8337481964f6d.tar.xz | |
Move fgetline out into misc.c.
I'm about to want to use it outside the GTK front end.
Diffstat (limited to 'misc.c')
| -rw-r--r-- | misc.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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) { |