From 6bc39ff78cf2f7fe8f799ce31b1b43640113ace9 Mon Sep 17 00:00:00 2001 From: YoungJules Date: Mon, 31 Aug 2026 13:20:30 +0200 Subject: [PATCH] Fix pm3line fallback for ProxSpace/MinGW builds --- client/src/pm3line.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/client/src/pm3line.c b/client/src/pm3line.c index 137eacce3..51d03b72e 100644 --- a/client/src/pm3line.c +++ b/client/src/pm3line.c @@ -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 }