Make ego put its temporary files in the right place.

This commit is contained in:
David Given 2022-07-17 21:09:18 +02:00
parent 28d4480f62
commit 739b9af662
6 changed files with 21 additions and 26 deletions

View file

@ -6,8 +6,9 @@ clibrary {
--"./lock.c", --"./lock.c",
"./modtime.c", "./open.c", "./read.c", "./remove.c", "./modtime.c", "./open.c", "./read.c", "./remove.c",
"./rename.c", "./seek.c", "./stop.c", "./system.c", "./rename.c", "./seek.c", "./stop.c", "./system.c",
--"./unlock.c”,”./tmpdir.c”, --"./unlock.c”,
"./write.c", "./write.c",
"./tmpdir.c",
"./syssystem.c", "./syssystem.c",
"./strndup.c", "./strndup.c",
"./setbinarymode.c", "./setbinarymode.c",

View file

@ -11,17 +11,24 @@ char* sys_gettmpdir(void)
char* result = 0; char* result = 0;
/* Check the UNIX temporary directory */ /* Check the UNIX temporary directory */
result = getenv("TMPDIR"); result = getenv("TMPDIR");
if (result != 0) if (result)
return result; return result;
result = getenv("TMP"); result = getenv("TMP");
if (result != 0) if (result)
return result; return result;
/* DOS compatible systems */ /* DOS compatible systems */
result = getenv("TEMP"); result = getenv("temp");
if (result != 0) if (result)
return result; return result;
/* Then try current directory */ result = getenv("TEMP");
if (result)
return result;
/* Then try and guess. */
#if defined WIN32
return "."; return ".";
#else
return "/tmp";
#endif
} }

View file

@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "system.h"
#include "ack.h" #include "ack.h"
#include "list.h" #include "list.h"
#include "trans.h" #include "trans.h"
@ -54,18 +55,7 @@ int setfiles(trf *phase) {
} else { } else {
gr_init(&pathname) ; gr_init(&pathname) ;
if ( !phase->t_keep && !t_flag ) { if ( !phase->t_keep && !t_flag ) {
/* Unix temporary directory. */ gr_cat(&pathname, sys_gettmpdir());
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, "/Ack-XXXXXX"); gr_cat(&pathname, "/Ack-XXXXXX");
int fd = mkstemp(pathname.gr_string); int fd = mkstemp(pathname.gr_string);
close(fd); close(fd);

View file

@ -177,6 +177,7 @@ cprogram {
"./il/il.h", "./il/il.h",
"util/ego/share+lib", "util/ego/share+lib",
"modules/src/em_data+lib", "modules/src/em_data+lib",
"modules/src/system+lib",
"h+emheaders", "h+emheaders",
}, },
vars = { vars = {

View file

@ -390,10 +390,7 @@ int main(int argc, char* argv[])
} }
{ {
char* tmpdir = getenv("TMPDIR"); strcpy(tmpbase, sys_gettmpdir());
if (!tmpdir)
tmpdir = "/tmp";
strcpy(tmpbase, tmpdir);
strcat(tmpbase, "/ego.XXXXXX"); strcat(tmpbase, "/ego.XXXXXX");
close(mkstemp(tmpbase)); close(mkstemp(tmpbase));
} }

View file

@ -12,6 +12,7 @@
#include <em_path.h> #include <em_path.h>
#include <em_mnem.h> #include <em_mnem.h>
#include <em_pseu.h> #include <em_pseu.h>
#include "system.h"
#include "../share/types.h" #include "../share/types.h"
#include "il.h" #include "il.h"
#include "../share/debug.h" #include "../share/debug.h"
@ -331,12 +332,10 @@ char* argv[];
{ {
struct files* files = findfiles(argc, argv); struct files* files = findfiles(argc, argv);
FILE* f; FILE* f;
char* tmpdir = getenv("TMPDIR"); char* tmpdir = sys_gettmpdir();
go(argc, argv, no_action, no_action, no_action, il_flags); go(argc, argv, no_action, no_action, no_action, il_flags);
il_extptab(fproc); /* add extended data structures */ il_extptab(fproc); /* add extended data structures */
if (!tmpdir)
tmpdir = "/tmp";
strcpy(cname, tmpdir); strcpy(cname, tmpdir);
strcpy(ccname, tmpdir); strcpy(ccname, tmpdir);