temporary file names
Keith Bostic
keith at seismo.UUCP
Mon Sep 24 07:08:10 AEST 1984
> --- REFERENCED ARTICLE ---------------------------------------------
>
> >From: keith at seismo.UUCP (Keith Bostic)
> >Date: Mon, 17-Sep-84 15:08:51 PDT
> >
> >This is a dangerous fix on EUNICE machines. The EUNICE shell does not
> >increment process id's as expected under UNIX.
>
> --------------------------------------------------------------------
> That is true...but `mktemp' works anyway. As suggested, `mktemp'
> just tries to stick the PID on then end of your template. If that
> already exists, it inserts an `a' before the PID. If that exists,
> it tries it with a `b'. The result is that I will personally double
> your money back guarantee you that you will be able to get at least
> 27 unique filenames for a given process ID. What `mktemp' does after
> `z', I'm not sure. Who knows...maybe someday I'll find out the *hard*
> way.
Okay -- go for it -- put this in your system *instead* of mktemp and all
your nasty little problems go away. Because, interestingly enough,
mktemp returns "/" after 'z'. Which is probably one of the most brain-
damaged pieces of software written since the world began.
Anyway -- here is a mktemp that gets around the problem EUNICE has in
incrementing the process id, 'cause it will give you more temporary files
than a cat will kittens. It's behavior (up to 'z') is identical to the
standard versions, and it's just as fast, if not faster.
Keith
ARPA: keith at seismo
UUCP: seismo!keith
............... cut on the dotted line.................
#include <ctype.h>
char *
mktemp(as)
register char *as;
{
register char *start, /* note start of X's */
*trv; /* travel through string */
unsigned pid;
pid = getpid();
for(trv = as;*trv;++trv); /* fill in pid */
while(*--trv == 'X') {
*trv = (pid % 10) + '0';
pid /= 10;
}
for(start = ++trv;;) {
if (access(as,0)) return(as);
for(trv = start;;) {
if (!*trv) return((char *)0);
if (*trv == 'z') *trv++ = 'a';
else {
if (isdigit(*trv)) *trv = 'a';
else ++*trv;
break;
}
}
}
}
More information about the Comp.os.eunice
mailing list