Replace mkstemp() with the more modern and safer and simpler tmpfile().

This commit is contained in:
David Given 2019-02-10 14:36:15 +01:00
parent 63fa647bc9
commit c95d5db372
3 changed files with 2 additions and 46 deletions

View file

@ -53,7 +53,6 @@ extern short bflag; /* -b option (no optimizations) */
#endif #endif
extern char *aoutpath INIT("a.out"); extern char *aoutpath INIT("a.out");
extern char temppath[50];
extern FILE *input; extern FILE *input;
extern FILE *tempfile; extern FILE *tempfile;
@ -93,7 +92,6 @@ extern short listcolm; /* column on output */
extern short listeoln INIT(1); extern short listeoln INIT(1);
/* set by endline, tested by emit1 */ /* set by endline, tested by emit1 */
extern FILE *listfile; /* copy of source text */ extern FILE *listfile; /* copy of source text */
extern char listpath[50];
#endif #endif
#ifndef extern #ifndef extern
@ -155,8 +153,6 @@ void emit4(long);
void emitx(valu_t, int); void emitx(valu_t, int);
void emitf(int size, int negative); void emitf(int size, int negative);
void emitstr(int); void emitstr(int);
FILE *ffcreat(char *);
FILE *fftemp(char *, char *);
void yyerror(const char *); void yyerror(const char *);
void nosect(void); void nosect(void);
void fatal(const char *, ...); void fatal(const char *, ...);

View file

@ -32,12 +32,6 @@ static void commfinish(void);
/* ========== Machine independent C routines ========== */ /* ========== Machine independent C routines ========== */
void stop(void) { void stop(void) {
#if DEBUG < 2
unlink(temppath);
#ifdef LISTING
unlink(listpath);
#endif
#endif
exit(nerrors != 0); exit(nerrors != 0);
} }
@ -78,13 +72,6 @@ main(int argc, char **argv)
fatal("-o needs filename"); fatal("-o needs filename");
aoutpath = argv[i]; aoutpath = argv[i];
break; break;
case 'T':
if (*p != '\0') {
extern char *tmp_dir;
tmp_dir = p;
}
break;
case 'd': case 'd':
#ifdef LISTING #ifdef LISTING
dflag = 0; dflag = 0;
@ -154,11 +141,11 @@ pass_1(int argc, char **argv)
nbits = BITCHUNK; nbits = BITCHUNK;
#endif #endif
tempfile = fftemp(temppath, "asTXXXXXX"); tempfile = tmpfile();
#ifdef LISTING #ifdef LISTING
listmode = dflag; listmode = dflag;
if (listmode & 0440) if (listmode & 0440)
listfile = fftemp(listpath, "asLXXXXXX"); listfile = tmpfile();
#endif #endif
for (ip = keytab; ip->i_type; ip++) for (ip = keytab; ip->i_type; ip++)
item_insert(ip, H_KEY+hash(ip->i_name)); item_insert(ip, H_KEY+hash(ip->i_name));

View file

@ -387,33 +387,6 @@ void emitf(int size, int negative)
con_float(stringbuf, size); con_float(stringbuf, size);
} }
/* ---------- Error checked file I/O ---------- */
FILE* ffcreat(char* s)
{
FILE* f;
if ((f = fopen(s, "w+")) == NULL)
fatal("can't create %s", s);
return (f);
}
#ifndef TMPDIR
#define TMPDIR "/tmp"
#endif
char* tmp_dir = TMPDIR;
FILE* fftemp(char* path, char* tail)
{
char* dir;
if ((dir = getenv("TMPDIR")) == NULL)
dir = tmp_dir;
sprintf(path, "%s/%s", dir, tail);
close(mkstemp(path));
return (ffcreat(path));
}
/* ---------- Error handling ---------- */ /* ---------- Error handling ---------- */
/* ARGSUSED */ /* ARGSUSED */