aboutsummaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2018-04-22 13:58:27 +0100
committerSimon Tatham <anakin@pobox.com>2018-04-22 16:35:50 +0100
commitb7034aeb51a99336fca2e15837c8337481964f6d (patch)
treef1e4fb0a418bec69e36ac6ab084467f338235f07 /misc.c
parent12cb1adc886078d715abbc04e80912703340f496 (diff)
downloadpuzzles-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.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index b6a190b..852f869 100644
--- a/misc.c
+++ b/misc.c
@@ -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)
{