Eliminate the TMP_DIR compile-time constant in favour of using $TMPDIR and

mkstemp where possible.
This commit is contained in:
David Given 2022-05-29 00:44:28 +02:00
parent 00cb4144f2
commit 76060c4dde
7 changed files with 35 additions and 35 deletions

View file

@ -3,7 +3,6 @@ normalrule {
ins = {}, ins = {},
outleaves = { "em_path.h" }, outleaves = { "em_path.h" },
commands = { commands = {
"echo '#define TMP_DIR \"/tmp\"' > %{outs}",
"echo '#define EM_DIR \"$(PREFIX)\"' >> %{outs}", "echo '#define EM_DIR \"$(PREFIX)\"' >> %{outs}",
"echo '#define ACK_PATH \"share/ack/descr\"' >> %{outs}", "echo '#define ACK_PATH \"share/ack/descr\"' >> %{outs}",
} }

View file

@ -39,8 +39,6 @@ int n_error = 0; /* Number of errors encountered */
char* progname = NULL; /* The program call name */ char* progname = NULL; /* The program call name */
char* outfile = NULL; /* The result file e.g. a.out */ char* outfile = NULL; /* The result file e.g. a.out */
char template[20] = {}; /* The template for temporary file
names */
trf* linker = NULL; /* Pointer to the Loader/Linker */ trf* linker = NULL; /* Pointer to the Loader/Linker */
trf* cpp_trafo = NULL; /* Pointer to C-preprocessor */ trf* cpp_trafo = NULL; /* Pointer to C-preprocessor */

View file

@ -38,8 +38,6 @@ extern int n_error; /* Number of errors encountered */
extern char* progname; /* The program call name */ extern char* progname; /* The program call name */
extern char* outfile; /* The result file e.g. a.out */ extern char* outfile; /* The result file e.g. a.out */
extern char template[20]; /* The template for temporary file
names */
extern trf* linker; /* Pointer to the Loader/Linker */ extern trf* linker; /* Pointer to the Loader/Linker */
extern trf* cpp_trafo; /* Pointer to C-preprocessor */ extern trf* cpp_trafo; /* Pointer to C-preprocessor */

View file

@ -26,18 +26,6 @@ static char *add_u(int part, char *ptr) {
return ptr+1 ; return ptr+1 ;
} }
static char *unique(void) {
/* Get the next unique part of the internal filename */
static int u_next = 0 ;
static char buf[10] ;
register char *ptr ;
ptr=add_u(u_next,buf) ;
*ptr=0 ;
u_next++ ;
return buf ;
}
int setfiles(trf *phase) { int setfiles(trf *phase) {
/* Set the out structure according to the in structure, /* Set the out structure according to the in structure,
the transformation and some global data */ the transformation and some global data */
@ -66,15 +54,16 @@ int setfiles(trf *phase) {
} else { } else {
gr_init(&pathname) ; gr_init(&pathname) ;
if ( !phase->t_keep && !t_flag ) { if ( !phase->t_keep && !t_flag ) {
gr_cat(&pathname,TMP_DIR) ; char* tmpdir = getenv("TMPDIR");
gr_cat(&pathname,"/") ; if (!tmpdir)
gr_cat(&pathname,template) ; tmpdir = "/tmp";
gr_cat(&pathname,unique()) ; gr_cat(&pathname, tmpdir);
gr_cat(&pathname, "/Ack-XXXXXX");
mkstemp(pathname.gr_string);
out.p_keep=NO ; out.p_keep=NO ;
} else { } else {
if ( !p_basename ) { if ( !p_basename ) {
gr_cat(&pathname,"Ack") ; gr_cat(&pathname,"Ack") ;
gr_cat(&pathname,unique()) ;
p_basename=keeps(gr_start(pathname)) ; p_basename=keeps(gr_start(pathname)) ;
werror("Output written on %s%s", werror("Output written on %s%s",
p_basename,phase->t_out) ; p_basename,phase->t_out) ;

View file

@ -83,7 +83,6 @@ int main(int argc, char** argv)
} }
transini(); transini();
scanneeds(); scanneeds();
sprintf(template, TMPNAME, getpid());
if (n_error && !k_flag) if (n_error && !k_flag)
exit(n_error); exit(n_error);

View file

@ -13,6 +13,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include "em_path.h" #include "em_path.h"
#include "system.h" #include "system.h"
#include "print.h" #include "print.h"
@ -59,12 +60,10 @@ static const struct
#define MAXARGS 1024 /* mar # of args */ #define MAXARGS 1024 /* mar # of args */
#define NTEMPS 4 /* # of temporary files; not tunable */ #define NTEMPS 4 /* # of temporary files; not tunable */
static char tmpbase[] = TMP_DIR "/ego.XXXXXX"; static char tmpbase[NAME_MAX];
static char ddump[128] = TMP_DIR; /* data label dump file */ static char ddump[NAME_MAX]; /* data label dump file */
static char pdump[128] = TMP_DIR; /* procedure name dump file */ static char pdump[NAME_MAX]; /* procedure name dump file */
static char tmpbufs[NTEMPS * 2][128] = { static char tmpbufs[NTEMPS * 2][NAME_MAX];
TMP_DIR
};
static int O2phases[] = { /* Passes for -O2 */ static int O2phases[] = { /* Passes for -O2 */
CJ, BO, SP, 0 CJ, BO, SP, 0
@ -407,7 +406,15 @@ int main(int argc, char* argv[])
fatal("no correct -P flag given"); fatal("no correct -P flag given");
} }
{
char* tmpdir = getenv("TMPDIR");
if (!tmpdir)
tmpdir = "/tmp";
strcpy(tmpbase, tmpdir);
strcat(tmpbase, "/ego.XXXXXX");
close(mkstemp(tmpbase)); close(mkstemp(tmpbase));
}
strcpy(ddump, tmpbase); strcpy(ddump, tmpbase);
strcpy(pdump, tmpbase); strcpy(pdump, tmpbase);
strcpy(tmpbufs[0], tmpbase); strcpy(tmpbufs[0], tmpbase);

View file

@ -29,6 +29,7 @@
#include "../share/get.h" #include "../share/get.h"
#include "../share/put.h" #include "../share/put.h"
#include "../share/go.h" #include "../share/go.h"
#include <limits.h>
int calnr; int calnr;
int complete_program; int complete_program;
@ -36,11 +37,12 @@ calcnt_p cchead; /* call-count info of current proc */
STATIC long space = 0; STATIC long space = 0;
STATIC long total_size = 0; STATIC long total_size = 0;
STATIC char cname[128] = TMP_DIR; STATIC char cname[NAME_MAX];
STATIC char ccname[128] = TMP_DIR; STATIC char ccname[NAME_MAX];
STATIC char cname2[NAME_MAX];
/* For debugging only */ /* For debugging only */
STATIC char sname[128] = TMP_DIR; STATIC char sname[NAME_MAX];
STATIC int kp_temps = 0; STATIC int kp_temps = 0;
int Ssubst; int Ssubst;
@ -125,8 +127,6 @@ STATIC void pass1(const char *lnam, const char *bnam, const char *cnam)
* be expanded in line. It does not use the EM text. * be expanded in line. It does not use the EM text.
*/ */
STATIC char cname2[128] = TMP_DIR;
STATIC void pass2(const char *cnam, long space) STATIC void pass2(const char *cnam, long space)
{ {
FILE* cf, *cf2, *ccf; FILE* cf, *cf2, *ccf;
@ -331,13 +331,23 @@ char* argv[];
{ {
struct files* files = findfiles(argc, argv); struct files* files = findfiles(argc, argv);
FILE* f; FILE* f;
char* tmpdir = getenv("TMPDIR");
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(ccname, tmpdir);
strcpy(sname, tmpdir);
strcpy(cname2, tmpdir);
strcat(cname, "/ego.i1.XXXXXX"); strcat(cname, "/ego.i1.XXXXXX");
strcat(ccname, "/ego.i2.XXXXXX"); strcat(ccname, "/ego.i2.XXXXXX");
strcat(sname, "/ego.i3.XXXXXX"); strcat(sname, "/ego.i3.XXXXXX");
strcat(cname2, "/ego.i4.XXXXXX"); strcat(cname2, "/ego.i4.XXXXXX");
close(mkstemp(cname)); close(mkstemp(cname));
close(mkstemp(ccname)); close(mkstemp(ccname));
close(mkstemp(sname)); close(mkstemp(sname));