From 739b9af662d55d339a66c64ebcdcd3abf35f8479 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 17 Jul 2022 21:09:18 +0200 Subject: [PATCH] Make ego put its temporary files in the right place. --- modules/src/system/build.lua | 3 ++- modules/src/system/tmpdir.c | 19 +++++++++++++------ util/ack/files.c | 14 ++------------ util/ego/build.lua | 1 + util/ego/em_ego/em_ego.c | 5 +---- util/ego/il/il.c | 5 ++--- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/modules/src/system/build.lua b/modules/src/system/build.lua index 4c2b8e52d..343c60fb3 100644 --- a/modules/src/system/build.lua +++ b/modules/src/system/build.lua @@ -6,8 +6,9 @@ clibrary { --"./lock.c", "./modtime.c", "./open.c", "./read.c", "./remove.c", "./rename.c", "./seek.c", "./stop.c", "./system.c", - --"./unlock.cā€,ā€./tmpdir.cā€, + --"./unlock.cā€, "./write.c", + "./tmpdir.c", "./syssystem.c", "./strndup.c", "./setbinarymode.c", diff --git a/modules/src/system/tmpdir.c b/modules/src/system/tmpdir.c index d02a91b0f..f41de61fa 100644 --- a/modules/src/system/tmpdir.c +++ b/modules/src/system/tmpdir.c @@ -11,17 +11,24 @@ char* sys_gettmpdir(void) char* result = 0; /* Check the UNIX temporary directory */ result = getenv("TMPDIR"); - if (result != 0) + if (result) return result; result = getenv("TMP"); - if (result != 0) + if (result) return result; /* DOS compatible systems */ - result = getenv("TEMP"); - if (result != 0) + result = getenv("temp"); + if (result) return result; - /* Then try current directory */ - return "."; + result = getenv("TEMP"); + if (result) + return result; + /* Then try and guess. */ + #if defined WIN32 + return "."; + #else + return "/tmp"; + #endif } diff --git a/util/ack/files.c b/util/ack/files.c index 4890b4b8c..04167e2e5 100644 --- a/util/ack/files.c +++ b/util/ack/files.c @@ -7,6 +7,7 @@ #include #include #include +#include "system.h" #include "ack.h" #include "list.h" #include "trans.h" @@ -54,18 +55,7 @@ int setfiles(trf *phase) { } else { gr_init(&pathname) ; if ( !phase->t_keep && !t_flag ) { - /* Unix temporary directory. */ - char* tmpdir = getenv("TMPDIR"); - /* Fallback: Windows, running under MSYS2. */ - if (!tmpdir) - tmpdir = getenv("temp"); - /* Fallback: Windows, running natively. */ - if (!tmpdir) - tmpdir = getenv("TEMP"); - /* Fallback: Hard-coded directory. */ - if (!tmpdir) - tmpdir = "/tmp"; - gr_cat(&pathname, tmpdir); + gr_cat(&pathname, sys_gettmpdir()); gr_cat(&pathname, "/Ack-XXXXXX"); int fd = mkstemp(pathname.gr_string); close(fd); diff --git a/util/ego/build.lua b/util/ego/build.lua index 8fbf43bca..5d7768e7e 100644 --- a/util/ego/build.lua +++ b/util/ego/build.lua @@ -177,6 +177,7 @@ cprogram { "./il/il.h", "util/ego/share+lib", "modules/src/em_data+lib", + "modules/src/system+lib", "h+emheaders", }, vars = { diff --git a/util/ego/em_ego/em_ego.c b/util/ego/em_ego/em_ego.c index 0ca4476b0..31364c298 100644 --- a/util/ego/em_ego/em_ego.c +++ b/util/ego/em_ego/em_ego.c @@ -390,10 +390,7 @@ int main(int argc, char* argv[]) } { - char* tmpdir = getenv("TMPDIR"); - if (!tmpdir) - tmpdir = "/tmp"; - strcpy(tmpbase, tmpdir); + strcpy(tmpbase, sys_gettmpdir()); strcat(tmpbase, "/ego.XXXXXX"); close(mkstemp(tmpbase)); } diff --git a/util/ego/il/il.c b/util/ego/il/il.c index 1f3455538..478053ab6 100644 --- a/util/ego/il/il.c +++ b/util/ego/il/il.c @@ -12,6 +12,7 @@ #include #include #include +#include "system.h" #include "../share/types.h" #include "il.h" #include "../share/debug.h" @@ -331,12 +332,10 @@ char* argv[]; { struct files* files = findfiles(argc, argv); FILE* f; - char* tmpdir = getenv("TMPDIR"); + char* tmpdir = sys_gettmpdir(); go(argc, argv, no_action, no_action, no_action, il_flags); il_extptab(fproc); /* add extended data structures */ - if (!tmpdir) - tmpdir = "/tmp"; strcpy(cname, tmpdir); strcpy(ccname, tmpdir);