xref: /netbsd-src/lib/libc/stdio/mkstemp.c (revision 017500be430b31a8e5d5f54ceeabdd78d346dc69)
1*017500beSchristos /*	$NetBSD: mkstemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $	*/
2201e4eacSmycroft 
3201e4eacSmycroft /*
4201e4eacSmycroft  * Copyright (c) 1987, 1993
5201e4eacSmycroft  *	The Regents of the University of California.  All rights reserved.
6201e4eacSmycroft  *
7201e4eacSmycroft  * Redistribution and use in source and binary forms, with or without
8201e4eacSmycroft  * modification, are permitted provided that the following conditions
9201e4eacSmycroft  * are met:
10201e4eacSmycroft  * 1. Redistributions of source code must retain the above copyright
11201e4eacSmycroft  *    notice, this list of conditions and the following disclaimer.
12201e4eacSmycroft  * 2. Redistributions in binary form must reproduce the above copyright
13201e4eacSmycroft  *    notice, this list of conditions and the following disclaimer in the
14201e4eacSmycroft  *    documentation and/or other materials provided with the distribution.
15eb7c1594Sagc  * 3. Neither the name of the University nor the names of its contributors
16201e4eacSmycroft  *    may be used to endorse or promote products derived from this software
17201e4eacSmycroft  *    without specific prior written permission.
18201e4eacSmycroft  *
19201e4eacSmycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20201e4eacSmycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21201e4eacSmycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22201e4eacSmycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23201e4eacSmycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24201e4eacSmycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25201e4eacSmycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26201e4eacSmycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27201e4eacSmycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28201e4eacSmycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29201e4eacSmycroft  * SUCH DAMAGE.
30201e4eacSmycroft  */
31*017500beSchristos #include "gettemp.h"
3292252507Sthorpej 
33171d6532Slukem #if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP
3492252507Sthorpej 
35201e4eacSmycroft #include <sys/cdefs.h>
36201e4eacSmycroft #if defined(LIBC_SCCS) && !defined(lint)
37201e4eacSmycroft #if 0
38201e4eacSmycroft static char sccsid[] = "@(#)mktemp.c	8.1 (Berkeley) 6/4/93";
39201e4eacSmycroft #else
40*017500beSchristos __RCSID("$NetBSD: mkstemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $");
41201e4eacSmycroft #endif
42201e4eacSmycroft #endif /* LIBC_SCCS and not lint */
43201e4eacSmycroft 
44fd5cb0acSkleink #ifdef __weak_alias
__weak_alias(mkstemp,_mkstemp)45fd5cb0acSkleink __weak_alias(mkstemp,_mkstemp)
46fd5cb0acSkleink #endif
47fd5cb0acSkleink 
48201e4eacSmycroft int
49526d9427Schristos mkstemp(char *path)
50201e4eacSmycroft {
51201e4eacSmycroft 	int fd;
52201e4eacSmycroft 
53b48252f3Slukem 	_DIAGASSERT(path != NULL);
54b48252f3Slukem 
55*017500beSchristos 	return GETTEMP(path, &fd, 0, 0, 0) ? fd : -1;
56201e4eacSmycroft }
5792252507Sthorpej 
58171d6532Slukem #endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP */
59