From 02f428a76d7f48a7e6c079afb9c560a460afb648 Mon Sep 17 00:00:00 2001 From: Sads Date: Wed, 17 Jun 2026 02:24:07 +0200 Subject: [PATCH] config: parse config.txt by hand instead of fgets() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Read the whole file with fread() and split on '\n' manually rather than using fgets() per line. Originally a workaround for a Vita3K *web* (wasm interpreter) bug that mis-scanned fgets's newline (so server= captured the whole file); that interpreter bug is since fixed, so this is now redundant on the web build, but it's correct and harmless on native Vita too — keeping it as a defensive, emulator-independent parser. Co-Authored-By: Claude Opus 4.8 --- src/config.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 71b1cb9..cfb8c9c 100644 --- a/src/config.c +++ b/src/config.c @@ -48,9 +48,21 @@ static int load_config(void) return -1; } - char line[512]; - while (fgets(line, sizeof(line), f)) { - char *s = clean_line(line); + /* Manual line split instead of fgets(): the Vita3K *web* (wasm interpreter) build + * mis-scans fgets's newline and returns the whole file as one line, so server= + * captured every following line too. Read the file whole and split on '\n' by hand + * (fread + a plain char loop avoid the broken libc path). Native Vita is unaffected. */ + char fbuf[4096]; + size_t flen = fread(fbuf, 1, sizeof(fbuf) - 1, f); + fbuf[flen] = '\0'; + char *lp = fbuf; + while (*lp) { + char *eol = lp; + while (*eol && *eol != '\n') + eol++; + char eolsave = *eol; + *eol = '\0'; + char *s = clean_line(lp); if (!strncmp(s, "server=", 7)) snprintf(g_server, sizeof(g_server), "%s", clean_line(s + 7)); else if (!strncmp(s, "apikey=", 7)) @@ -74,6 +86,9 @@ static int load_config(void) } } else if (!strncmp(s, "syncmaxmb=", 10)) g_syncmax_mb = atol(clean_line(s + 10)); + if (!eolsave) + break; + lp = eol + 1; } fclose(f);