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",
"./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",

View file

@ -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 */
result = getenv("TEMP");
if (result)
return result;
/* Then try and guess. */
#if defined WIN32
return ".";
#else
return "/tmp";
#endif
}

View file

@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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);

View file

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

View file

@ -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));
}

View file

@ -12,6 +12,7 @@
#include <em_path.h>
#include <em_mnem.h>
#include <em_pseu.h>
#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);