lib: don't give back the same temporary filenames even if removed.
workaround for what seems to be a clang/llvm bug/assumption.
This commit is contained in:
parent
4fcd34137c
commit
8d24932c80
@ -71,6 +71,8 @@ _gettemp(path, doopen)
|
|||||||
register char *start, *trv;
|
register char *start, *trv;
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
u_int pid;
|
u_int pid;
|
||||||
|
static int lastnames = 0;
|
||||||
|
int names = 0;
|
||||||
|
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
for (trv = path; *trv; ++trv); /* extra X's get set to 0's */
|
for (trv = path; *trv; ++trv); /* extra X's get set to 0's */
|
||||||
@ -100,16 +102,6 @@ _gettemp(path, doopen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (doopen) {
|
|
||||||
if ((*doopen =
|
|
||||||
open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0)
|
|
||||||
return(1);
|
|
||||||
if (errno != EEXIST)
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
else if (stat(path, &sbuf))
|
|
||||||
return(errno == ENOENT ? 1 : 0);
|
|
||||||
|
|
||||||
/* tricky little algorithm for backward compatibility */
|
/* tricky little algorithm for backward compatibility */
|
||||||
for (trv = start;;) {
|
for (trv = start;;) {
|
||||||
if (!*trv)
|
if (!*trv)
|
||||||
@ -124,6 +116,27 @@ _gettemp(path, doopen)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
names++;
|
||||||
|
|
||||||
|
if(names <= lastnames)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
lastnames = names;
|
||||||
|
|
||||||
|
if (doopen) {
|
||||||
|
if ((*doopen =
|
||||||
|
open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) {
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
if (errno != EEXIST) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (stat(path, &sbuf)) {
|
||||||
|
return(errno == ENOENT ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user