Replace mkstemp() with the more modern and safer and simpler tmpfile().
This commit is contained in:
parent
63fa647bc9
commit
c95d5db372
|
@ -53,7 +53,6 @@ extern short bflag; /* -b option (no optimizations) */
|
|||
#endif
|
||||
|
||||
extern char *aoutpath INIT("a.out");
|
||||
extern char temppath[50];
|
||||
|
||||
extern FILE *input;
|
||||
extern FILE *tempfile;
|
||||
|
@ -93,7 +92,6 @@ extern short listcolm; /* column on output */
|
|||
extern short listeoln INIT(1);
|
||||
/* set by endline, tested by emit1 */
|
||||
extern FILE *listfile; /* copy of source text */
|
||||
extern char listpath[50];
|
||||
#endif
|
||||
|
||||
#ifndef extern
|
||||
|
@ -155,8 +153,6 @@ void emit4(long);
|
|||
void emitx(valu_t, int);
|
||||
void emitf(int size, int negative);
|
||||
void emitstr(int);
|
||||
FILE *ffcreat(char *);
|
||||
FILE *fftemp(char *, char *);
|
||||
void yyerror(const char *);
|
||||
void nosect(void);
|
||||
void fatal(const char *, ...);
|
||||
|
|
|
@ -32,12 +32,6 @@ static void commfinish(void);
|
|||
/* ========== Machine independent C routines ========== */
|
||||
|
||||
void stop(void) {
|
||||
#if DEBUG < 2
|
||||
unlink(temppath);
|
||||
#ifdef LISTING
|
||||
unlink(listpath);
|
||||
#endif
|
||||
#endif
|
||||
exit(nerrors != 0);
|
||||
}
|
||||
|
||||
|
@ -78,13 +72,6 @@ main(int argc, char **argv)
|
|||
fatal("-o needs filename");
|
||||
aoutpath = argv[i];
|
||||
break;
|
||||
case 'T':
|
||||
if (*p != '\0') {
|
||||
extern char *tmp_dir;
|
||||
|
||||
tmp_dir = p;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
#ifdef LISTING
|
||||
dflag = 0;
|
||||
|
@ -154,11 +141,11 @@ pass_1(int argc, char **argv)
|
|||
nbits = BITCHUNK;
|
||||
#endif
|
||||
|
||||
tempfile = fftemp(temppath, "asTXXXXXX");
|
||||
tempfile = tmpfile();
|
||||
#ifdef LISTING
|
||||
listmode = dflag;
|
||||
if (listmode & 0440)
|
||||
listfile = fftemp(listpath, "asLXXXXXX");
|
||||
listfile = tmpfile();
|
||||
#endif
|
||||
for (ip = keytab; ip->i_type; ip++)
|
||||
item_insert(ip, H_KEY+hash(ip->i_name));
|
||||
|
|
|
@ -387,33 +387,6 @@ void emitf(int size, int negative)
|
|||
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 ---------- */
|
||||
|
||||
/* ARGSUSED */
|
||||
|
|
Loading…
Reference in a new issue