Some cleanup.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1765 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-05-25 02:36:43 +00:00
parent 7d0d793c35
commit 36c0ba1517

View File

@@ -56,34 +56,32 @@ RCSID("$Id$");
int int
mkstemp(char *template) mkstemp(char *template)
{ {
int i, j; int start, i;
unsigned long val; pid_t val;
val = getpid(); val = getpid();
i = strlen(template) - 1; start = strlen(template) - 1;
while(template[i] == 'X') { while(template[start] == 'X') {
template[i] = '0' + val % 10; template[start] = '0' + val % 10;
val /= 10; val /= 10;
i--; start--;
} }
do{ do{
int fd; int fd;
fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600); fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
if(fd >= 0) if(fd >= 0 || errno != EEXIST)
return fd; return fd;
if(fd < 0 && errno != EEXIST) i = start + 1;
return -1;
j = i + 1;
do{ do{
if(template[j] == 0) if(template[i] == 0)
return -1; return -1;
template[j]++; template[i]++;
if(template[j] == '9' + 1) if(template[i] == '9' + 1)
template[j] = 'a'; template[i] = 'a';
if(template[j] <= 'z') if(template[i] <= 'z')
break; break;
template[j] = 'a'; template[i] = 'a';
j++; i++;
}while(1); }while(1);
}while(1); }while(1);
} }