1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Torek. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #if defined(LIBC_SCCS) && !defined(lint) 12 static char sccsid[] = "@(#)tmpfile.c 5.1 (Berkeley) 01/20/91"; 13 #endif /* LIBC_SCCS and not lint */ 14 15 #include <sys/param.h> 16 #include <stdio.h> 17 #include <errno.h> 18 19 FILE * 20 tmpfile() 21 { 22 FILE *fp; 23 int e; 24 char *f, buf[MAXPATHLEN]; 25 26 if ((f = tmpnam(buf)) == NULL) 27 return (NULL); 28 fp = fopen(f, "w+"); 29 e = errno; 30 (void) unlink(f); 31 errno = e; 32 return (fp); 33 } 34