From e3ab29bb4d7174cae65de2275f19105eb3d93d91 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Sun, 25 Jan 2026 18:24:05 +0000 Subject: APE shall never kill APE --- src/repl/repl.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/repl/repl.c') diff --git a/src/repl/repl.c b/src/repl/repl.c index 22fe95d..274c14c 100644 --- a/src/repl/repl.c +++ b/src/repl/repl.c @@ -28,6 +28,12 @@ void run_repl(const char *self_path) char history_path[512]; const char *home = getenv("HOME"); +#ifdef _WIN32 + if (!home) + { + home = getenv("USERPROFILE"); + } +#endif if (home) { snprintf(history_path, sizeof(history_path), "%s/.zprep_history", home); @@ -262,7 +268,16 @@ void run_repl(const char *self_path) } char edit_path[256]; - sprintf(edit_path, "/tmp/zprep_edit_%d.zc", rand()); + const char *tmpdir = getenv("TEMP"); + if (!tmpdir) + { + tmpdir = getenv("TMP"); + } + if (!tmpdir) + { + tmpdir = "/tmp"; + } + snprintf(edit_path, sizeof(edit_path), "%s/zprep_edit_%d.zc", tmpdir, rand()); FILE *f = fopen(edit_path, "w"); if (f) { @@ -638,7 +653,17 @@ void run_repl(const char *self_path) strcat(probe_code, "); }"); char tmp_path[256]; - sprintf(tmp_path, "/tmp/zprep_repl_type_%d.zc", rand()); + const char *tmpdir = getenv("TEMP"); + if (!tmpdir) + { + tmpdir = getenv("TMP"); + } + if (!tmpdir) + { + tmpdir = "/tmp"; + } + snprintf(tmp_path, sizeof(tmp_path), "%s/zprep_repl_type_%d.zc", tmpdir, + rand()); FILE *f = fopen(tmp_path, "w"); if (f) { @@ -722,7 +747,17 @@ void run_repl(const char *self_path) strcat(code, "}"); char tmp_path[256]; - sprintf(tmp_path, "/tmp/zprep_repl_time_%d.zc", rand()); + const char *tmpdir = getenv("TEMP"); + if (!tmpdir) + { + tmpdir = getenv("TMP"); + } + if (!tmpdir) + { + tmpdir = "/tmp"; + } + snprintf(tmp_path, sizeof(tmp_path), "%s/zprep_repl_time_%d.zc", tmpdir, + rand()); FILE *f = fopen(tmp_path, "w"); if (f) { -- cgit v1.2.3