/* THIS FILE HAS BEEN MODIFIED FROM THE ORIGINAL OPENBSD SOURCE */
/* Changes: Removed mktemp */
+/* $OpenBSD: mktemp.c,v 1.19 2005/08/08 08:05:36 espie Exp $ */
/*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+/* OPENBSD ORIGINAL: lib/libc/stdio/mktemp.c */
+
#include "includes.h"
-#ifndef HAVE_MKDTEMP
+#include <sys/types.h>
+#include <sys/stat.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: mktemp.c,v 1.14 2002/01/02 20:18:32 deraadt Exp $";
-#endif /* LIBC_SCCS and not lint */
+#include <fcntl.h>
+#include <ctype.h>
+#include <errno.h>
+#include <unistd.h>
-#ifdef HAVE_CYGWIN
-#define open binary_open
-extern int binary_open();
-#endif
+#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
static int _gettemp(char *, int *, int, int);
int
-mkstemps(path, slen)
- char *path;
- int slen;
+mkstemps(char *path, int slen)
{
int fd;
}
int
-mkstemp(path)
- char *path;
+mkstemp(char *path)
{
int fd;
}
char *
-mkdtemp(path)
- char *path;
+mkdtemp(char *path)
{
return(_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL);
}
return (0);
}
pid = getpid();
- while (*trv == 'X' && pid != 0) {
+ while (trv >= path && *trv == 'X' && pid != 0) {
*trv-- = (pid % 10) + '0';
pid /= 10;
}
- while (*trv == 'X') {
+ while (trv >= path && *trv == 'X') {
char c;
pid = (arc4random() & 0xffff) % (26+26);
/*NOTREACHED*/
}
-#endif /* !HAVE_MKDTEMP */
+#endif /* !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) */