mkstemp() is a bit more complex than it looks; because ego wants to use the
same base name and generate multiple files based on it, we can't really use mkstemp() for every temporary file. Instead, use mkstemp() once on a placeholder, then generate temporary names based on this. (And delete the placeholder once we've finished.)
This commit is contained in:
parent
a96c846a29
commit
1203e8afd2
|
@ -58,6 +58,7 @@ 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 ddump[128] = TMP_DIR; /* data label dump file */
|
static char ddump[128] = TMP_DIR; /* data label dump file */
|
||||||
static char pdump[128] = TMP_DIR; /* procedure name dump file */
|
static char pdump[128] = TMP_DIR; /* procedure name dump file */
|
||||||
static char tmpbufs[NTEMPS * 2][128] = {
|
static char tmpbufs[NTEMPS * 2][128] = {
|
||||||
|
@ -115,6 +116,8 @@ cleanup()
|
||||||
if (pdump[0] != '\0')
|
if (pdump[0] != '\0')
|
||||||
(void)unlink(pdump);
|
(void)unlink(pdump);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void)unlink(tmpbase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*VARARGS1*/
|
/*VARARGS1*/
|
||||||
|
@ -200,9 +203,8 @@ new_outfiles()
|
||||||
char** dst = &phargs[NTEMPS + 1];
|
char** dst = &phargs[NTEMPS + 1];
|
||||||
|
|
||||||
if (!Bindex)
|
if (!Bindex)
|
||||||
{
|
Bindex = strlen(tmpbufs[0]) - 2;
|
||||||
Bindex = strrchr(tmpbufs[0], 'B') - tmpbufs[0];
|
|
||||||
}
|
|
||||||
for (i = 1; i <= NTEMPS; i++)
|
for (i = 1; i <= NTEMPS; i++)
|
||||||
{
|
{
|
||||||
*dst = tmpbufs[tmpindex];
|
*dst = tmpbufs[tmpindex];
|
||||||
|
@ -403,25 +405,25 @@ int main(int argc, char* argv[])
|
||||||
fatal("no correct -P flag given");
|
fatal("no correct -P flag given");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(mkstemp(tmpbase));
|
||||||
|
strcpy(ddump, tmpbase);
|
||||||
|
strcpy(pdump, tmpbase);
|
||||||
|
strcpy(tmpbufs[0], tmpbase);
|
||||||
|
|
||||||
if (keeptemps)
|
if (keeptemps)
|
||||||
{
|
{
|
||||||
(void)strcpy(ddump, ".");
|
(void)strcpy(ddump, ".");
|
||||||
(void)strcpy(pdump, ".");
|
(void)strcpy(pdump, ".");
|
||||||
(void)strcpy(tmpbufs[0], ".");
|
(void)strcpy(tmpbufs[0], ".");
|
||||||
}
|
}
|
||||||
(void)strcat(ddump, "/ego.dd.XXXXXX");
|
(void)strcat(ddump, "dd");
|
||||||
close(mkstemp(ddump));
|
(void)strcat(pdump, "pd");
|
||||||
(void)strcat(pdump, "/ego.pd.XXXXXX");
|
|
||||||
close(mkstemp(pdump));
|
|
||||||
|
|
||||||
(void)strcat(tmpbufs[0], "/ego.XXXXXX");
|
(void)strcat(tmpbufs[0], "A.BB");
|
||||||
close(mkstemp(tmpbufs[0]));
|
for (i=1; i<(2 * NTEMPS); i++)
|
||||||
(void)strcat(tmpbufs[0], ".A.BB");
|
|
||||||
for (i = 2 * NTEMPS - 1; i >= 1; i--)
|
|
||||||
{
|
|
||||||
(void)strcpy(tmpbufs[i], tmpbufs[0]);
|
(void)strcpy(tmpbufs[i], tmpbufs[0]);
|
||||||
}
|
|
||||||
i = strrchr(tmpbufs[0], 'A') - tmpbufs[0];
|
i = strlen(tmpbufs[0]) - 4;
|
||||||
tmpbufs[0][i] = 'p';
|
tmpbufs[0][i] = 'p';
|
||||||
tmpbufs[NTEMPS + 0][i] = 'p';
|
tmpbufs[NTEMPS + 0][i] = 'p';
|
||||||
tmpbufs[1][i] = 'd';
|
tmpbufs[1][i] = 'd';
|
||||||
|
@ -430,6 +432,7 @@ int main(int argc, char* argv[])
|
||||||
tmpbufs[NTEMPS + 2][i] = 'l';
|
tmpbufs[NTEMPS + 2][i] = 'l';
|
||||||
tmpbufs[3][i] = 'b';
|
tmpbufs[3][i] = 'b';
|
||||||
tmpbufs[NTEMPS + 3][i] = 'b';
|
tmpbufs[NTEMPS + 3][i] = 'b';
|
||||||
|
|
||||||
run_phase(IC);
|
run_phase(IC);
|
||||||
run_phase(CF);
|
run_phase(CF);
|
||||||
while (*Ophase)
|
while (*Ophase)
|
||||||
|
|
Loading…
Reference in a new issue