| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id$";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* Replacement mktemp(3) function for systems without
|
| 6 |
*/
|
| 7 |
|
| 8 |
#include "copyright.h"
|
| 9 |
|
| 10 |
#define NULL 0
|
| 11 |
|
| 12 |
|
| 13 |
char *
|
| 14 |
mktemp(template) /* make a unique filename from template */
|
| 15 |
char *template;
|
| 16 |
{
|
| 17 |
register char *tb, *te, *p;
|
| 18 |
int pid;
|
| 19 |
/* find string of 6 (opt) X's */
|
| 20 |
for (te = template; *te; te++)
|
| 21 |
;
|
| 22 |
while (te > template && te[-1] != 'X')
|
| 23 |
te--;
|
| 24 |
if (te == template)
|
| 25 |
return(template); /* no X's! */
|
| 26 |
for (tb = te; tb > template && tb[-1] == 'X'; tb--)
|
| 27 |
;
|
| 28 |
if (te-tb > 6) /* only need 6 chars */
|
| 29 |
tb = te-6;
|
| 30 |
pid = getpid(); /* 5 (opt) chars of pid */
|
| 31 |
for (p = te-2; p >= tb; p--) {
|
| 32 |
*p = pid%10 + '0';
|
| 33 |
pid /= 10;
|
| 34 |
}
|
| 35 |
p = te-1; /* final character */
|
| 36 |
for (*p = 'a'; *p <= 'z'; (*p)++)
|
| 37 |
if (access(template, 0) == -1)
|
| 38 |
return(template); /* found unique name */
|
| 39 |
return(NULL); /* failure! */
|
| 40 |
}
|