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

/*
 * libc/gen/mktemp.c
 * 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; by steve, 1/5/93.
 * Avoids unsuitable characters in generator.
 * Repeats after 26+26+10+1=63 invocations by the same process.
 */

char *
mktemp(template) char *template;
{
	static char generator = 'a';
	register char *p;
	register int i, pid;


	for (p = template; *p; p++)
		;				/* scan to end of template */
	*--p = generator;			/* store generator */
	switch (generator)  {			/* bump generator */
	case 'z':	generator = 'A';		break;
	case 'Z':	generator = '0';		break;
	case '9':	generator = '_';		break;
	case '_':	generator = 'a';		break;
	default:	++generator;			break;
	}
	pid = getpid();
	for (i = 5; i-- > 0; ) {		/* store 5-digit ASCII pid */
		*--p = pid%10 + '0';
		pid /= 10;
	}
	return template;
}

/* end of libc/gen/mktemp.c */

unix.superglobalmegacorp.com

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