Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site seismo.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxj!ihnp4!zehntel!hplabs!hao!seismo!keith
From: keith@seismo.UUCP (Keith Bostic)
Newsgroups: net.eunice
Subject: Re: temporary file names
Message-ID: <4162@seismo.UUCP>
Date: Sun, 23-Sep-84 17:08:10 EDT
Article-I.D.: seismo.4162
Posted: Sun Sep 23 17:08:10 1984
Date-Received: Wed, 26-Sep-84 05:47:42 EDT
References: <4006@seismo.UUCP> <1132@t4test.UUCP>
Distribution: net.all
Organization: Center for Seismic Studies, Arlington, VA
Lines: 63

> --- REFERENCED ARTICLE ---------------------------------------------
> 
> >From: keith@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@seismo 
			UUCP: seismo!keith

............... cut on the dotted line.................

#include 

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;
			}
		}
	}
}