config: parse config.txt by hand instead of fgets()
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 <noreply@anthropic.com>
This commit is contained in:
+18
-3
@@ -48,9 +48,21 @@ static int load_config(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char line[512];
|
/* Manual line split instead of fgets(): the Vita3K *web* (wasm interpreter) build
|
||||||
while (fgets(line, sizeof(line), f)) {
|
* mis-scans fgets's newline and returns the whole file as one line, so server=
|
||||||
char *s = clean_line(line);
|
* 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))
|
if (!strncmp(s, "server=", 7))
|
||||||
snprintf(g_server, sizeof(g_server), "%s", clean_line(s + 7));
|
snprintf(g_server, sizeof(g_server), "%s", clean_line(s + 7));
|
||||||
else if (!strncmp(s, "apikey=", 7))
|
else if (!strncmp(s, "apikey=", 7))
|
||||||
@@ -74,6 +86,9 @@ static int load_config(void)
|
|||||||
}
|
}
|
||||||
} else if (!strncmp(s, "syncmaxmb=", 10))
|
} else if (!strncmp(s, "syncmaxmb=", 10))
|
||||||
g_syncmax_mb = atol(clean_line(s + 10));
|
g_syncmax_mb = atol(clean_line(s + 10));
|
||||||
|
if (!eolsave)
|
||||||
|
break;
|
||||||
|
lp = eol + 1;
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user