Fix pm3line fallback for ProxSpace/MinGW builds

This commit is contained in:
YoungJules authored and Philippe Teuwen committed 2026-09-01 14:20:12 +02:00
1 parent 18aed4eaa4
commit 6bc39ff78c
1 file changed
+16 -8
+16 -8
View File
@@ -193,15 +193,23 @@ char *pm3line_read(const char *s) {
return linenoise(s);
#else
printf("%s", s);
char *answer = NULL;
size_t anslen = 0;
int ret;
if ((ret = getline(&answer, &anslen, stdin)) < 0) {
// TODO this happens also when kbd_enter_pressed() is used, with a key pressed or not
printf("DEBUG: getline returned %i", ret);
free(answer);
answer = NULL;
// MinGW/ProxSpace builds do not provide getline() in this fallback path.
char input[1024] = {0};
if (fgets(input, sizeof(input), stdin) == NULL) {
return NULL;
}
size_t len = strlen(input);
while (len > 0 && (input[len - 1] == '\n' || input[len - 1] == '\r')) {
input[--len] = '\0';
}
char *answer = calloc(len + 1, sizeof(char));
if (answer == NULL) {
return NULL;
}
memcpy(answer, input, len);
return answer;
#endif
}