mkstemp.c revision 1.8
11.8Slukem/*	$NetBSD: mkstemp.c,v 1.8 2003/10/27 00:12:42 lukem Exp $	*/
21.1Smycroft
31.1Smycroft/*
41.1Smycroft * Copyright (c) 1987, 1993
51.1Smycroft *	The Regents of the University of California.  All rights reserved.
61.1Smycroft *
71.1Smycroft * Redistribution and use in source and binary forms, with or without
81.1Smycroft * modification, are permitted provided that the following conditions
91.1Smycroft * are met:
101.1Smycroft * 1. Redistributions of source code must retain the above copyright
111.1Smycroft *    notice, this list of conditions and the following disclaimer.
121.1Smycroft * 2. Redistributions in binary form must reproduce the above copyright
131.1Smycroft *    notice, this list of conditions and the following disclaimer in the
141.1Smycroft *    documentation and/or other materials provided with the distribution.
151.7Sagc * 3. Neither the name of the University nor the names of its contributors
161.1Smycroft *    may be used to endorse or promote products derived from this software
171.1Smycroft *    without specific prior written permission.
181.1Smycroft *
191.1Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Smycroft * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Smycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Smycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Smycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Smycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Smycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Smycroft * SUCH DAMAGE.
301.1Smycroft */
311.1Smycroft
321.8Slukem#if HAVE_NBTOOL_CONFIG_H
331.8Slukem#include "nbtool_config.h"
341.5Sthorpej#endif
351.5Sthorpej
361.8Slukem#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP
371.5Sthorpej
381.1Smycroft#include <sys/cdefs.h>
391.1Smycroft#if defined(LIBC_SCCS) && !defined(lint)
401.1Smycroft#if 0
411.1Smycroftstatic char sccsid[] = "@(#)mktemp.c	8.1 (Berkeley) 6/4/93";
421.1Smycroft#else
431.8Slukem__RCSID("$NetBSD: mkstemp.c,v 1.8 2003/10/27 00:12:42 lukem Exp $");
441.1Smycroft#endif
451.1Smycroft#endif /* LIBC_SCCS and not lint */
461.1Smycroft
471.8Slukem#if HAVE_NBTOOL_CONFIG_H
481.5Sthorpej#define	GETTEMP		gettemp
491.5Sthorpej#else
501.3Slukem#include <assert.h>
511.3Slukem#include <errno.h>
521.1Smycroft#include <stdio.h>
531.1Smycroft#include <stdlib.h>
541.1Smycroft#include <unistd.h>
551.6Sthorpej#include "reentrant.h"
561.1Smycroft#include "local.h"
571.5Sthorpej#define	GETTEMP		__gettemp
581.5Sthorpej#endif
591.1Smycroft
601.1Smycroftint
611.1Smycroftmkstemp(path)
621.1Smycroft	char *path;
631.1Smycroft{
641.1Smycroft	int fd;
651.3Slukem
661.3Slukem	_DIAGASSERT(path != NULL);
671.1Smycroft
681.5Sthorpej	return (GETTEMP(path, &fd, 0) ? fd : -1);
691.1Smycroft}
701.5Sthorpej
711.8Slukem#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP */
72