xref: /csrg-svn/lib/libc/stdio/tmpnam.c (revision 64893)
146111Sbostic /*-
261180Sbostic  * Copyright (c) 1990, 1993
361180Sbostic  *	The Regents of the University of California.  All rights reserved.
446111Sbostic  *
546111Sbostic  * This code is derived from software contributed to Berkeley by
646111Sbostic  * Chris Torek.
746111Sbostic  *
846111Sbostic  * %sccs.include.redist.c%
946111Sbostic  */
1046111Sbostic 
1146111Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*64893Sbostic static char sccsid[] = "@(#)tmpnam.c	8.2 (Berkeley) 11/16/93";
1346111Sbostic #endif /* LIBC_SCCS and not lint */
1446111Sbostic 
1546559Sbostic #include <unistd.h>
1646111Sbostic #include <stdio.h>
1746111Sbostic 
1846111Sbostic char *
1946111Sbostic tmpnam(s)
2046111Sbostic 	char *s;
2146111Sbostic {
22*64893Sbostic 	static unsigned long tmpcount;
2346559Sbostic 	static char buf[L_tmpnam];
2446111Sbostic 
2546111Sbostic 	if (s == NULL)
2646111Sbostic 		s = buf;
27*64893Sbostic 	(void)snprintf(s, L_tmpnam, "%s/tmp.%lu.XXXXXX", P_tmpdir, tmpcount);
28*64893Sbostic 	++tmpcount;
29*64893Sbostic 	return (mktemp(s));
3046111Sbostic }
31