tmpnam.c revision 1573
155682Smarkm/*- 2233294Sstas * Copyright (c) 1990, 1993, 1994 3233294Sstas * The Regents of the University of California. All rights reserved. 4233294Sstas * 555682Smarkm * This code is derived from software contributed to Berkeley by 6233294Sstas * Chris Torek. 7233294Sstas * 8233294Sstas * Redistribution and use in source and binary forms, with or without 955682Smarkm * modification, are permitted provided that the following conditions 10233294Sstas * are met: 11233294Sstas * 1. Redistributions of source code must retain the above copyright 1255682Smarkm * notice, this list of conditions and the following disclaimer. 13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 14233294Sstas * notice, this list of conditions and the following disclaimer in the 15233294Sstas * documentation and/or other materials provided with the distribution. 1655682Smarkm * 3. All advertising materials mentioning features or use of this software 17233294Sstas * must display the following acknowledgement: 18233294Sstas * This product includes software developed by the University of 19233294Sstas * California, Berkeley and its contributors. 2055682Smarkm * 4. Neither the name of the University nor the names of its contributors 21233294Sstas * may be used to endorse or promote products derived from this software 22233294Sstas * without specific prior written permission. 23233294Sstas * 24233294Sstas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27233294Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3255682Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3355682Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3455682Smarkm * SUCH DAMAGE. 3555682Smarkm */ 3655682Smarkm 3755682Smarkm#if defined(LIBC_SCCS) && !defined(lint) 3855682Smarkmstatic char sccsid[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94"; 3955682Smarkm#endif /* LIBC_SCCS and not lint */ 4078527Sassar 4155682Smarkm#include <sys/types.h> 4255682Smarkm 4355682Smarkm#include <stdio.h> 4455682Smarkm#include <unistd.h> 4555682Smarkm 4655682Smarkmchar * 4755682Smarkmtmpnam(s) 4855682Smarkm char *s; 4955682Smarkm{ 5055682Smarkm static u_long tmpcount; 5155682Smarkm static char buf[L_tmpnam]; 5278527Sassar 5378527Sassar if (s == NULL) 5455682Smarkm s = buf; 5555682Smarkm (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); 5655682Smarkm ++tmpcount; 5755682Smarkm return (mktemp(s)); 5855682Smarkm} 5955682Smarkm