File:  [MW Coherent from dump] / coherent / d / lib / libc / gen / mktemp.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:37 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * Produce a unique filename by replacing
 * the trailing 6 X's on the user's input string
 * with process id and a unique letter.
 * (It is assumed, but not checked, that the X's are present.)
 * Revised by Michael Griffin, 7-5-84.  Avoids control characters in
 * generator.  Repeats after 91 invocations by the same process.
 */

static	char	generator = 'a';

char *
mktemp(template)
char *template;
{
	register char *p;
	register i, pid;

	for (p = template; *p; p++)
		;
	switch (generator)  {
		case '~':
			*--p = generator;
			generator = 'A';
			break;
		case '_':
			*--p = generator;
			generator = '!';
			break;
		case '*':
			*--p = ++generator;
			generator++;
			break;
		case '?':
			*--p = (generator = '@');
			break;
		case '@':
			generator = 'a';
			*--p = generator++;
			break;
		default:
			*--p = generator++;
	}
	pid = getpid();
	i = 5; do {
		*--p = pid%10 + '0';
		pid /= 10;
	} while (--i);
	return (template);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.