diff options
author | kaa <kaa@disroot.org> | 2023-07-09 09:08:23 -0700 |
---|---|---|
committer | kaa <kaa@disroot.org> | 2023-07-09 09:08:23 -0700 |
commit | baee5248699451f570f6fdfe13ed53e4fe6e9f65 (patch) | |
tree | 20fced40766b3445a8020dc69c60055c26e981c2 /shared.h | |
parent | d72126cc5efc1cc5cca2de8960b13a24fee1c7e2 (diff) | |
download | neocities-baee5248699451f570f6fdfe13ed53e4fe6e9f65.tar.gz |
As it turns out, getline() is a POSIX extension, not included in Windows tcc or MinGW.
Diffstat (limited to 'shared.h')
-rw-r--r-- | shared.h | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/shared.h b/shared.h index 740984d..b4232ae 100644 --- a/shared.h +++ b/shared.h @@ -1 +1,22 @@ -char *site = "https://kaa.neocities.org/"; +static char * +storeline(FILE *in, int *end, int *len, int guess) +{ + static char *line; + line = calloc(guess, sizeof(char)); + int i = 0, buflen = guess; + char ch; + while ((ch = fgetc(in)) != EOF && ch != '\n') { + if (i == buflen - 1) { + buflen += guess; + line = realloc(line, buflen * sizeof(char)); + } + line[i] = ch; + ++i; + } + line[i] = '\0'; + *len = i; + if (ch == EOF) + *end = 1; + + return line; +} |