xref: /csrg-svn/lib/libc/stdio/tmpnam.c (revision 66508)
146111Sbostic /*-
2*66508Sbostic  * Copyright (c) 1990, 1993, 1994
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*66508Sbostic static char sccsid[] = "@(#)tmpnam.c	8.3 (Berkeley) 03/28/94";
1346111Sbostic #endif /* LIBC_SCCS and not lint */
1446111Sbostic 
15*66508Sbostic #include <sys/types.h>
16*66508Sbostic 
17*66508Sbostic #include <stdio.h>
1846559Sbostic #include <unistd.h>
1946111Sbostic 
2046111Sbostic char *
tmpnam(s)2146111Sbostic tmpnam(s)
2246111Sbostic 	char *s;
2346111Sbostic {
24*66508Sbostic 	static u_long tmpcount;
2546559Sbostic 	static char buf[L_tmpnam];
2646111Sbostic 
2746111Sbostic 	if (s == NULL)
2846111Sbostic 		s = buf;
29*66508Sbostic 	(void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount);
3064893Sbostic 	++tmpcount;
3164893Sbostic 	return (mktemp(s));
3246111Sbostic }
33