From a96023ced1af1ed44bb6ce28aac3f12749ea2843 Mon Sep 17 00:00:00 2001 From: William Bell <62452284+Ugric@users.noreply.github.com> Date: Mon, 18 Aug 2025 15:03:11 +0100 Subject: [PATCH] fix for winblows --- src/shell.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/shell.c b/src/shell.c index 8b37094..93bdc86 100644 --- a/src/shell.c +++ b/src/shell.c @@ -20,14 +20,21 @@ #endif #if defined(_WIN32) || defined(_WIN64) FILE *fmemopen(void *buf, size_t size, const char *mode) { - FILE *fp = tmpfile(); - if (!fp) return NULL; - - if (strchr(mode, 'w') || strchr(mode, '+')) { - fwrite(buf, 1, size, fp); - rewind(fp); + if (strchr(mode, 'r') == NULL) { + return NULL; } - return fp; + + FILE *tmp = tmpfile(); + if (!tmp) return NULL; + + if (fwrite(buf, 1, size, tmp) != size) { + fclose(tmp); + return NULL; + } + + rewind(tmp); + + return tmp; } #else #include "../external/linenoise/linenoise.h"