mkstemp.c revision 1.3
11.3Slukem/*	$NetBSD: mkstemp.c,v 1.3 1999/09/16 11:45:29 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.1Smycroft * 3. All advertising materials mentioning features or use of this software
161.1Smycroft *    must display the following acknowledgement:
171.1Smycroft *	This product includes software developed by the University of
181.1Smycroft *	California, Berkeley and its contributors.
191.1Smycroft * 4. Neither the name of the University nor the names of its contributors
201.1Smycroft *    may be used to endorse or promote products derived from this software
211.1Smycroft *    without specific prior written permission.
221.1Smycroft *
231.1Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
241.1Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
251.1Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261.1Smycroft * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
271.1Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
281.1Smycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
291.1Smycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301.1Smycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311.1Smycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321.1Smycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331.1Smycroft * SUCH DAMAGE.
341.1Smycroft */
351.1Smycroft
361.1Smycroft#include <sys/cdefs.h>
371.1Smycroft#if defined(LIBC_SCCS) && !defined(lint)
381.1Smycroft#if 0
391.1Smycroftstatic char sccsid[] = "@(#)mktemp.c	8.1 (Berkeley) 6/4/93";
401.1Smycroft#else
411.3Slukem__RCSID("$NetBSD: mkstemp.c,v 1.3 1999/09/16 11:45:29 lukem Exp $");
421.1Smycroft#endif
431.1Smycroft#endif /* LIBC_SCCS and not lint */
441.1Smycroft
451.3Slukem#include <assert.h>
461.3Slukem#include <errno.h>
471.1Smycroft#include <stdio.h>
481.1Smycroft#include <stdlib.h>
491.1Smycroft#include <unistd.h>
501.1Smycroft#include "local.h"
511.1Smycroft
521.1Smycroftint
531.1Smycroftmkstemp(path)
541.1Smycroft	char *path;
551.1Smycroft{
561.1Smycroft	int fd;
571.3Slukem
581.3Slukem	_DIAGASSERT(path != NULL);
591.3Slukem#ifdef _DIAGNOSTIC
601.3Slukem	if (path == NULL || *path == '\0') {
611.3Slukem		errno = ENOENT;
621.3Slukem		return (NULL);
631.3Slukem	}
641.3Slukem#endif
651.1Smycroft
661.2Smycroft	return (__gettemp(path, &fd, 0) ? fd : -1);
671.1Smycroft}
68