PSARC/2006/107 mkstemps(3C)/mkdtemp(3C)
authorcasper
Thu, 23 Feb 2006 04:39:12 -0800
changeset 1475 0c7070c5774f
parent 1474 00024dd3f95c
child 1476 64aa6463c09c
PSARC/2006/107 mkstemps(3C)/mkdtemp(3C) 6386057 Add mkdtemp(3C)/mkstemps(3C)
usr/src/cmd/mktemp/mktemp.c
usr/src/cmd/perl/5.6.1/i386/config.sh
usr/src/cmd/perl/5.6.1/sparc/config.sh
usr/src/cmd/perl/5.8.4/i386/config.sh
usr/src/cmd/perl/5.8.4/sparc/config.sh
usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.6.1/5.11/i386/Config.pm
usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.6.1/5.11/sparc/Config.pm
usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.8.4/5.11/i386/Config.pm
usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.8.4/5.11/sparc/Config.pm
usr/src/cmd/ssh/include/config.h
usr/src/head/stdlib.h
usr/src/lib/common/inc/c_synonyms.h
usr/src/lib/libc/amd64/Makefile
usr/src/lib/libc/i386/Makefile.com
usr/src/lib/libc/inc/synonyms.h
usr/src/lib/libc/port/gen/mkdtemp.c
usr/src/lib/libc/port/gen/mkstemp.c
usr/src/lib/libc/port/gen/mktemp.c
usr/src/lib/libc/sparc/Makefile
usr/src/lib/libc/sparcv9/Makefile
usr/src/lib/libc/spec/gen.spec
usr/src/lib/libc/spec/interface64.spec
--- a/usr/src/cmd/mktemp/mktemp.c	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/mktemp/mktemp.c	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  * Create unique plain files or directories.
@@ -31,10 +30,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <errno.h>
 #include <string.h>
 #include <locale.h>
-#include <sys/stat.h>
 
 static void
 usage(void)
@@ -45,38 +42,6 @@
 	/* NOTREACHED */
 }
 
-static int
-mktmpdir(char *tmpl)
-{
-	char *tx = strdup(tmpl);
-	int i;
-
-	if (tx == NULL) {
-		perror("strdup");
-		exit(1);
-	}
-	for (i = 0; i < 100; i++) {
-		if (*mktemp(tmpl) == '\0')
-			goto errout;
-
-		if (mkdir(tmpl, 0700) == 0) {
-			free(tx);
-			return (0);
-		}
-
-		/* All other errors won't be fixed by trying a different name */
-		if (errno != EEXIST)
-			goto errout;
-
-		/* Restore template for next try */
-		(void) strcpy(tmpl, tx);
-	}
-errout:
-	(void) strcpy(tmpl, tx);
-	free(tx);
-	return (-1);
-}
-
 int
 main(int argc, char **argv)
 {
@@ -161,7 +126,7 @@
 	}
 
 	if (domkdir) {
-		if (mktmpdir(tmpl) != 0) {
+		if (mkdtemp(tmpl) == NULL) {
 			if (!quiet) {
 				(void) fprintf(stderr,
 				    gettext("mktemp: failed to create "
--- a/usr/src/cmd/perl/5.6.1/i386/config.sh	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/5.6.1/i386/config.sh	Thu Feb 23 04:39:12 2006 -0800
@@ -231,10 +231,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='undef'
--- a/usr/src/cmd/perl/5.6.1/sparc/config.sh	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/5.6.1/sparc/config.sh	Thu Feb 23 04:39:12 2006 -0800
@@ -231,10 +231,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='undef'
--- a/usr/src/cmd/perl/5.8.4/i386/config.sh	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/5.8.4/i386/config.sh	Thu Feb 23 04:39:12 2006 -0800
@@ -285,10 +285,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='define'
--- a/usr/src/cmd/perl/5.8.4/sparc/config.sh	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/5.8.4/sparc/config.sh	Thu Feb 23 04:39:12 2006 -0800
@@ -284,10 +284,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='define'
--- a/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.6.1/5.11/i386/Config.pm	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.6.1/5.11/i386/Config.pm	Thu Feb 23 04:39:12 2006 -0800
@@ -291,10 +291,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='undef'
--- a/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.6.1/5.11/sparc/Config.pm	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.6.1/5.11/sparc/Config.pm	Thu Feb 23 04:39:12 2006 -0800
@@ -291,10 +291,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='undef'
--- a/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.8.4/5.11/i386/Config.pm	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.8.4/5.11/i386/Config.pm	Thu Feb 23 04:39:12 2006 -0800
@@ -391,10 +391,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='define'
--- a/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.8.4/5.11/sparc/Config.pm	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/perl/contrib/Sun/Solaris/PerlGcc/config/5.8.4/5.11/sparc/Config.pm	Thu Feb 23 04:39:12 2006 -0800
@@ -391,10 +391,10 @@
 d_memmove='define'
 d_memset='define'
 d_mkdir='define'
-d_mkdtemp='undef'
+d_mkdtemp='define'
 d_mkfifo='define'
 d_mkstemp='define'
-d_mkstemps='undef'
+d_mkstemps='define'
 d_mktime='define'
 d_mmap='define'
 d_modfl='define'
--- a/usr/src/cmd/ssh/include/config.h	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/cmd/ssh/include/config.h	Thu Feb 23 04:39:12 2006 -0800
@@ -2,7 +2,7 @@
 /* config.h.in.  Generated from configure.ac by autoheader.  */
 /* $Id: acconfig.h,v 1.145 2002/09/26 00:38:48 tim Exp $ */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -969,6 +969,10 @@
 /* Define if compiling in ON */
 #define SUNW_SSH 1
 
+/* Define if you have mkstemp, mkstemps and mkdtemp */
+#define	HAVE_MKDTEMP
+
+
 /* ******************* Shouldn't need to edit below this line ************** */
 
 #ifdef __cplusplus
--- a/usr/src/head/stdlib.h	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/head/stdlib.h	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -98,8 +97,10 @@
 
 #ifdef	__PRAGMA_REDEFINE_EXTNAME
 #pragma redefine_extname	mkstemp		mkstemp64
+#pragma redefine_extname	mkstemps	mkstemps64
 #else	/* __PRAGMA_REDEFINE_EXTNAME */
 #define	mkstemp			mkstemp64
+#define	mkstemps		mkstemps64
 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
 
 #endif	/* _FILE_OFFSET_BITS == 64 */
@@ -109,8 +110,10 @@
 
 #ifdef	__PRAGMA_REDEFINE_EXTNAME
 #pragma redefine_extname	mkstemp64	mkstemp
+#pragma redefine_extname	mkstemps64	mkstemps
 #else	/* __PRAGMA_REDEFINE_EXTNAME */
 #define	mkstemp64		mkstemp
+#define	mkstemps64		mkstemps
 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
 
 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
@@ -166,11 +169,13 @@
 	!defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
 	(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
 extern int	mkstemp(char *);
+extern int	mkstemps(char *, int);
 #endif /* defined(__EXTENSIONS__) ... */
 
 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
 extern int	mkstemp64(char *);
+extern int	mkstemps64(char *, int);
 #endif	/* _LARGEFILE64_SOURCE... */
 
 #if defined(__EXTENSIONS__) || \
@@ -226,6 +231,7 @@
 extern int isatty(int);
 extern void *memalign(size_t, size_t);
 extern char *ttyname(int);
+extern char *mkdtemp(char *);
 
 #if !defined(_STRICT_STDC) && defined(_LONGLONG_TYPE)
 extern char *lltostr(long long, char *);
@@ -266,11 +272,13 @@
 	!defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
 	(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64)
 extern int	mkstemp();
+extern int	mkstemps();
 #endif	/* defined(__EXTENSIONS__) ... */
 
 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
 extern int	mkstemp64();
+extern int	mkstemps64();
 #endif	/* _LARGEFILE64_SOURCE... */
 
 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)
@@ -320,6 +328,7 @@
 extern int isatty();
 extern void *memalign();
 extern char *ttyname();
+extern char *mkdtemp();
 
 #if defined(_LONGLONG_TYPE)
 extern char *lltostr();
--- a/usr/src/lib/common/inc/c_synonyms.h	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/common/inc/c_synonyms.h	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -476,8 +475,10 @@
 #define	memset				_memset
 #define	mincore				_mincore
 #define	mkdir				_mkdir
+#define	mkdtemp				_mkdtemp
 #define	mkfifo				_mkfifo
 #define	mkstemp				_mkstemp
+#define	mkstemps			_mkstemps
 #define	mktemp				_mktemp
 #define	mlockall			_mlockall
 #define	mlock				_mlock
--- a/usr/src/lib/libc/amd64/Makefile	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/amd64/Makefile	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
 # CDDL HEADER START
 #
 # The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License").  You may not use this file except in compliance
-# with the License.
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
 #
 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 # or http://www.opensolaris.org/os/licensing.
@@ -457,6 +456,7 @@
 	malloc.o		\
 	memalign.o		\
 	mkdev.o			\
+	mkdtemp.o		\
 	mkfifo.o		\
 	mkstemp.o		\
 	mktemp.o		\
@@ -1046,7 +1046,7 @@
 
 $(LINTLIB):= SRCS=../port/llib-lc
 $(LINTLIB):= CPPFLAGS += -D_MSE_INT_H
-$(LINTLIB):= LINTFLAGS64=-nvx -Xarch=amd64 
+$(LINTLIB):= LINTFLAGS64=-nvx -Xarch=amd64
 
 # object files that depend on inline template
 $(TIL:%=pics/%): $(LIBCBASE)/threads/amd64.il
--- a/usr/src/lib/libc/i386/Makefile.com	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/i386/Makefile.com	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
 # CDDL HEADER START
 #
 # The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License").  You may not use this file except in compliance
-# with the License.
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
 #
 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 # or http://www.opensolaris.org/os/licensing.
@@ -489,6 +488,7 @@
 	malloc.o		\
 	memalign.o		\
 	mkdev.o			\
+	mkdtemp.o		\
 	mkfifo.o		\
 	mkstemp.o		\
 	mktemp.o		\
--- a/usr/src/lib/libc/inc/synonyms.h	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/inc/synonyms.h	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -58,6 +57,7 @@
 #define	lseek64			_lseek64
 #define	lstat64			_lstat64
 #define	mkstemp64		_mkstemp64
+#define	mkstemps64		_mkstemps64
 #define	mmap64			_mmap64
 #define	openat64		_openat64
 #define	open64			_open64
@@ -563,9 +563,11 @@
 #define	memset			_memset
 #define	mincore			_mincore
 #define	mkdir			_mkdir
+#define	mkdtemp			_mkdtemp
 #define	mkfifo			_mkfifo
 #define	mknod			_mknod
 #define	mkstemp			_mkstemp
+#define	mkstemps		_mkstemps
 #define	mktemp			_mktemp
 #define	mlockall		_mlockall
 #define	mlock			_mlock
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/lib/libc/port/gen/mkdtemp.c	Thu Feb 23 04:39:12 2006 -0800
@@ -0,0 +1,67 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident	"%Z%%M%	%I%	%E% SMI"
+
+/*
+ * mkdtemp(3C) - create a directory with a unique name.
+ */
+
+#pragma weak mkdtemp = _mkdtemp
+
+#include "synonyms.h"
+
+#include <alloca.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+char *
+mkdtemp(char *template)
+{
+	char *t = alloca(strlen(template) + 1);
+	char *r;
+
+	/* Save template */
+	(void) strcpy(t, template);
+	for (; ; ) {
+		r = mktemp(template);
+
+		if (*r == '\0')
+			return (NULL);
+
+		if (mkdir(template, 0700) == 0)
+			return (r);
+
+		/* Other errors indicate persistent conditions. */
+		if (errno != EEXIST)
+			return (NULL);
+
+		/* Reset template */
+		(void) strcpy(template, t);
+	}
+}
--- a/usr/src/lib/libc/port/gen/mkstemp.c	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/port/gen/mkstemp.c	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
  * Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
@@ -37,9 +36,13 @@
 
 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
 #pragma weak mkstemp64 = _mkstemp64
+#pragma weak mkstemps64 = _mkstemps64
 #define	_mkstemp	_mkstemp64
+#define	_mkstemps	_mkstemps64
+#define	libc_mkstemps	libc_mkstemps64		/* prefer unique statics */
 #else
 #pragma weak mkstemp = _mkstemp
+#pragma weak mkstemps = _mkstemps
 #endif
 
 #include "synonyms.h"
@@ -52,20 +55,26 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+extern char *libc_mktemps(char *, int);
 
-int
-_mkstemp(char *as)
+static int
+libc_mkstemps(char *as, int slen)
 {
 	int	fd;
+	int	len;
 	char	*tstr, *str, *mkret;
 
 	if (as == NULL || *as == NULL)
 		return (-1);
 
-	tstr = alloca(strlen(as) + 1);
+	len = (int)strlen(as);
+	tstr = alloca(len + 1);
 	(void) strcpy(tstr, as);
 
-	str = tstr + (strlen(tstr) - 1);
+	if (slen < 0 || slen >= len)
+		return (-1);
+
+	str = tstr + (len - 1 - slen);
 
 	/*
 	 * The following for() loop is doing work.  mktemp() will generate
@@ -75,7 +84,7 @@
 
 	for (; ; ) {
 		if (*str == 'X') { /* If no trailing X's don't call mktemp. */
-			mkret = mktemp(as);
+			mkret = libc_mktemps(as, slen);
 			if (*mkret == '\0') {
 				return (-1);
 			}
@@ -102,3 +111,15 @@
 		(void) strcpy(as, tstr);
 	}
 }
+
+int
+_mkstemp(char *as)
+{
+	return (libc_mkstemps(as, 0));
+}
+
+int
+_mkstemps(char *as, int slen)
+{
+	return (libc_mkstemps(as, slen));
+}
--- a/usr/src/lib/libc/port/gen/mktemp.c	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/port/gen/mktemp.c	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
  * CDDL HEADER START
  *
  * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
  *
  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  * or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -121,7 +120,7 @@
 }
 
 char *
-mktemp(char *as)
+libc_mktemps(char *as, int slen)
 {
 	/* statics are protected by this static mutex */
 	static mutex_t	mktemp_lock = DEFAULTMUTEX;
@@ -167,6 +166,9 @@
 	/* count the X's */
 	xcnt = 0;
 	len = (int)strlen(as);
+	if (slen >= len || slen < 0)
+		goto fail;
+	len -= slen;
 	s = as + (len - 1);
 	while ((len != 0) && (xcnt < XCNT) && (*s == 'X')) {
 		xcnt++;
@@ -249,3 +251,9 @@
 	*as = '\0';
 	return (as);
 }
+
+char *
+mktemp(char *template)
+{
+	return (libc_mktemps(template, 0));
+}
--- a/usr/src/lib/libc/sparc/Makefile	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/sparc/Makefile	Thu Feb 23 04:39:12 2006 -0800
@@ -1,10 +1,9 @@
-#
+
 # CDDL HEADER START
 #
 # The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License").  You may not use this file except in compliance
-# with the License.
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
 #
 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 # or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # ident	"%Z%%M%	%I%	%E% SMI"
@@ -513,6 +512,7 @@
 	malloc.o		\
 	memalign.o		\
 	mkdev.o			\
+	mkdtemp.o		\
 	mkfifo.o		\
 	mkstemp.o		\
 	mktemp.o		\
--- a/usr/src/lib/libc/sparcv9/Makefile	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/sparcv9/Makefile	Thu Feb 23 04:39:12 2006 -0800
@@ -2,9 +2,8 @@
 # CDDL HEADER START
 #
 # The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License").  You may not use this file except in compliance
-# with the License.
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
 #
 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 # or http://www.opensolaris.org/os/licensing.
@@ -475,6 +474,7 @@
 	malloc.o		\
 	memalign.o		\
 	mkdev.o			\
+	mkdtemp.o		\
 	mkfifo.o		\
 	mkstemp.o		\
 	mktemp.o		\
--- a/usr/src/lib/libc/spec/gen.spec	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/spec/gen.spec	Thu Feb 23 04:39:12 2006 -0800
@@ -1,13 +1,12 @@
 #
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # CDDL HEADER START
 #
 # The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License").  You may not use this file except in compliance
-# with the License.
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
 #
 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 # or http://www.opensolaris.org/os/licensing.
@@ -1019,7 +1018,7 @@
 function	_ftw
 weak		ftw
 version		SUNWprivate_1.1
-end		
+end
 
 function	gconvert
 include		<floatingpoint.h>
@@ -1088,10 +1087,10 @@
 		amd64=SUNW_0.7
 end
 
-function	getextmntent 
+function	getextmntent
 include		<stdio.h>, <sys/mnttab.h>
 declaration	int getextmntent(FILE *fp, struct extmnttab *mp, size_t len)
-version		SUNW_1.20 
+version		SUNW_1.20
 exception	$return != 0
 end
 
@@ -2014,6 +2013,18 @@
 		sparcv9=/platform/$PLATFORM/lib/sparcv9/libc_psr.so.1
 end
 
+function	mkdtemp
+include		<stdlib.h>
+declaration	char *mkdtemp(char *template)
+version		SUNW_1.22.1
+exception	$return == 0
+end
+
+function	_mkdtemp
+weak		mkdtemp
+version		SUNW_1.22.1
+end
+
 function	mkfifo
 include		<sys/types.h>, <sys/stat.h>
 declaration	int mkfifo(const char *path, mode_t mode)
@@ -2040,6 +2051,18 @@
 version         SUNW_0.7
 end
 
+function        mkstemps
+include         <stdlib.h>
+declaration     int mkstemps(char *template, int suffixlen)
+version         SUNW_1.22.1
+exception       $return == -1
+end
+
+function        _mkstemps
+weak            mkstemps
+version         SUNW_1.22.1
+end
+
 function	mktemp
 include		<stdlib.h>
 declaration	char *mktemp(char *template)
@@ -2595,7 +2618,7 @@
 weak		readdir
 version		sparc=SYSVABI_1.3 i386=SYSVABI_1.3 sparcv9=SUNW_0.7 \
 		amd64=SUNW_0.7
-end		
+end
 
 # NOTE: The declarations of the various versions of readdir_r()
 # in <dirent.h> are hopelessly convoluted, so we can't declare
@@ -2678,7 +2701,7 @@
 function	resetmnttab
 include		<stdio.h>, <sys/mnttab.h>
 declaration	void resetmnttab(FILE *fp)
-version		SUNW_1.20 
+version		SUNW_1.20
 end
 
 function	rewind
@@ -4202,7 +4225,7 @@
 
 function	priv_set
 include		<priv.h>
-declaration	int priv_set(priv_op_t, priv_ptype_t, ...) 
+declaration	int priv_set(priv_op_t, priv_ptype_t, ...)
 version		SUNW_1.22
 exception	$return != 0
 errno		ENOMEM EPERM EINVAL
@@ -4215,7 +4238,7 @@
 
 function	priv_str_to_set
 include		<priv.h>
-declaration	priv_set_t *priv_str_to_set(const char *, const char *, const char **) 
+declaration	priv_set_t *priv_str_to_set(const char *, const char *, const char **)
 version		SUNW_1.22
 exception	$return == 0
 errno		ENOMEM EINVAL
@@ -4261,7 +4284,7 @@
 
 function	__priv_getsetbynum
 include		<priv.h>
-declaration	const char *__priv_getsetbynum(int, void *) 
+declaration	const char *__priv_getsetbynum(int, void *)
 version		SUNW_1.22
 exception	$return == 0
 errno		EINVAL
@@ -4273,7 +4296,7 @@
 
 function	__priv_getbynum
 include		<priv.h>
-declaration	const char *__priv_getbynum(int, void *) 
+declaration	const char *__priv_getbynum(int, void *)
 version		SUNW_1.22
 exception	$return == 0
 errno		EINVAL
@@ -4281,7 +4304,7 @@
 
 function	priv_getbynum
 include		<priv.h>
-declaration	const char *priv_getbynum(int) 
+declaration	const char *priv_getbynum(int)
 version		SUNW_1.22
 exception	$return == 0
 errno		EINVAL
@@ -4294,7 +4317,7 @@
 
 function	priv_getsetbynum
 include		<priv.h>
-declaration	const char *priv_getsetbynum(int) 
+declaration	const char *priv_getsetbynum(int)
 version		SUNW_1.22
 exception	$return == 0
 errno		EINVAL
@@ -4307,7 +4330,7 @@
 
 function	__priv_getsetbyname
 include		<priv.h>
-declaration	int __priv_getsetbyname(const char *, void *) 
+declaration	int __priv_getsetbyname(const char *, void *)
 version		SUNW_1.22
 exception	$return == -1
 errno		EINVAL
@@ -4315,7 +4338,7 @@
 
 function	__priv_getbyname
 include		<priv.h>
-declaration	int __priv_getbyname(const char *, void *) 
+declaration	int __priv_getbyname(const char *, void *)
 version		SUNW_1.22
 exception	$return == -1
 errno		EINVAL
@@ -4323,7 +4346,7 @@
 
 function	priv_getbyname
 include		<priv.h>
-declaration	int priv_getbyname(const char *) 
+declaration	int priv_getbyname(const char *)
 version		SUNW_1.22
 exception	$return == -1
 errno		EINVAL
@@ -4336,7 +4359,7 @@
 
 function	priv_getsetbyname
 include		<priv.h>
-declaration	int priv_getsetbyname(const char *) 
+declaration	int priv_getsetbyname(const char *)
 version		SUNW_1.22
 exception	$return == -1
 errno		EINVAL
@@ -4349,7 +4372,7 @@
 
 function	priv_gettext
 include		<priv.h>
-declaration	char *priv_gettext(const char *) 
+declaration	char *priv_gettext(const char *)
 version		SUNW_1.22
 exception	$return == 0
 end
@@ -4361,7 +4384,7 @@
 
 function	priv_allocset
 include		<priv.h>
-declaration	priv_set_t *priv_allocset(void) 
+declaration	priv_set_t *priv_allocset(void)
 version		SUNW_1.22
 exception	$return == 0
 errno		ENOMEM
@@ -4374,7 +4397,7 @@
 
 function	priv_freeset
 include		<priv.h>
-declaration	void priv_freeset(priv_set_t *) 
+declaration	void priv_freeset(priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4385,7 +4408,7 @@
 
 function	priv_emptyset
 include		<priv.h>
-declaration	void priv_emptyset(priv_set_t *) 
+declaration	void priv_emptyset(priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4396,7 +4419,7 @@
 
 function	priv_fillset
 include		<priv.h>
-declaration	void priv_fillset(priv_set_t *) 
+declaration	void priv_fillset(priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4407,7 +4430,7 @@
 
 function	priv_isemptyset
 include		<priv.h>
-declaration	boolean_t priv_isemptyset(const priv_set_t *) 
+declaration	boolean_t priv_isemptyset(const priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4418,7 +4441,7 @@
 
 function	priv_isfullset
 include		<priv.h>
-declaration	boolean_t priv_isfullset(const priv_set_t *) 
+declaration	boolean_t priv_isfullset(const priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4429,7 +4452,7 @@
 
 function	priv_isequalset
 include		<priv.h>
-declaration	boolean_t priv_isequalset(const priv_set_t *, const priv_set_t *) 
+declaration	boolean_t priv_isequalset(const priv_set_t *, const priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4440,7 +4463,7 @@
 
 function	priv_issubset
 include		<priv.h>
-declaration	boolean_t priv_issubset(const priv_set_t *, const priv_set_t *) 
+declaration	boolean_t priv_issubset(const priv_set_t *, const priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4451,7 +4474,7 @@
 
 function	priv_intersect
 include		<priv.h>
-declaration	void priv_intersect(const priv_set_t *, priv_set_t *) 
+declaration	void priv_intersect(const priv_set_t *, priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4462,7 +4485,7 @@
 
 function	priv_union
 include		<priv.h>
-declaration	void priv_union(const priv_set_t *, priv_set_t *) 
+declaration	void priv_union(const priv_set_t *, priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4473,7 +4496,7 @@
 
 function	priv_inverse
 include		<priv.h>
-declaration	void priv_inverse(priv_set_t *) 
+declaration	void priv_inverse(priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4484,7 +4507,7 @@
 
 function	priv_addset
 include		<priv.h>
-declaration	int priv_addset(priv_set_t *, const char *) 
+declaration	int priv_addset(priv_set_t *, const char *)
 version		SUNW_1.22
 end
 
@@ -4495,7 +4518,7 @@
 
 function	priv_delset
 include		<priv.h>
-declaration	int priv_delset(priv_set_t *, const char *) 
+declaration	int priv_delset(priv_set_t *, const char *)
 version		SUNW_1.22
 end
 
@@ -4506,7 +4529,7 @@
 
 function	priv_copyset
 include		<priv.h>
-declaration	void priv_copyset(const priv_set_t *, priv_set_t *) 
+declaration	void priv_copyset(const priv_set_t *, priv_set_t *)
 version		SUNW_1.22
 end
 
@@ -4517,7 +4540,7 @@
 
 function	priv_ismember
 include		<priv.h>
-declaration	boolean_t priv_ismember(const priv_set_t *, const char *) 
+declaration	boolean_t priv_ismember(const priv_set_t *, const char *)
 version		SUNW_1.22
 end
 
@@ -4528,7 +4551,7 @@
 
 function	ucred_get
 include		<ucred.h>
-declaration	ucred_t *ucred_get(pid_t pid) 
+declaration	ucred_t *ucred_get(pid_t pid)
 version		SUNW_1.22
 end
 
@@ -4545,7 +4568,7 @@
 
 function	ucred_free
 include		<ucred.h>
-declaration	void ucred_free(ucred_t *) 
+declaration	void ucred_free(ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4556,7 +4579,7 @@
 
 function	ucred_geteuid
 include		<ucred.h>
-declaration	uid_t ucred_geteuid(const ucred_t *) 
+declaration	uid_t ucred_geteuid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4567,7 +4590,7 @@
 
 function	ucred_getruid
 include		<ucred.h>
-declaration	uid_t ucred_getruid(const ucred_t *) 
+declaration	uid_t ucred_getruid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4578,7 +4601,7 @@
 
 function	ucred_getsuid
 include		<ucred.h>
-declaration	uid_t ucred_getsuid(const ucred_t *) 
+declaration	uid_t ucred_getsuid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4589,7 +4612,7 @@
 
 function	ucred_getegid
 include		<ucred.h>
-declaration	gid_t ucred_getegid(const ucred_t *) 
+declaration	gid_t ucred_getegid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4600,7 +4623,7 @@
 
 function	ucred_getrgid
 include		<ucred.h>
-declaration	gid_t ucred_getrgid(const ucred_t *) 
+declaration	gid_t ucred_getrgid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4611,7 +4634,7 @@
 
 function	ucred_getsgid
 include		<ucred.h>
-declaration	gid_t ucred_getsgid(const ucred_t *) 
+declaration	gid_t ucred_getsgid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4622,7 +4645,7 @@
 
 function	ucred_getgroups
 include		<ucred.h>
-declaration	int ucred_getgroups(const ucred_t *, const gid_t **) 
+declaration	int ucred_getgroups(const ucred_t *, const gid_t **)
 version		SUNW_1.22
 end
 
@@ -4633,7 +4656,7 @@
 
 function	ucred_getprivset
 include		<ucred.h>
-declaration	const priv_set_t *ucred_getprivset(const ucred_t *, priv_ptype_t) 
+declaration	const priv_set_t *ucred_getprivset(const ucred_t *, priv_ptype_t)
 version		SUNW_1.22
 end
 
@@ -4644,7 +4667,7 @@
 
 function	ucred_getpid
 include		<ucred.h>
-declaration	pid_t ucred_getpid(const ucred_t *) 
+declaration	pid_t ucred_getpid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4655,7 +4678,7 @@
 
 function	ucred_getprojid
 include		<ucred.h>
-declaration	projid_t ucred_getprojid(const ucred_t *) 
+declaration	projid_t ucred_getprojid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4666,7 +4689,7 @@
 
 function	ucred_getzoneid
 include		<ucred.h>
-declaration	zoneid_t ucred_getzoneid(const ucred_t *) 
+declaration	zoneid_t ucred_getzoneid(const ucred_t *)
 version		SUNW_1.22
 end
 
@@ -4677,7 +4700,7 @@
 
 function	ucred_getpflags
 include		<ucred.h>
-declaration	uint_t ucred_getpflags(const ucred_t *, uint_t) 
+declaration	uint_t ucred_getpflags(const ucred_t *, uint_t)
 version		SUNW_1.22
 end
 
@@ -4686,7 +4709,7 @@
 version		SUNW_1.22
 end
 
-function	zonept	
+function	zonept
 include		<stdlib.h> <sys/zone.h>
 declaration	int zonept(int filedes, zoneid_t zoneid)
 version		SUNWprivate_1.1
@@ -4834,7 +4857,7 @@
 
 function	ucred_getauid
 include		<ucred.h>, <bsm/audit.h>
-declaration	au_id_t ucred_getauid(const ucred_t *) 
+declaration	au_id_t ucred_getauid(const ucred_t *)
 version		SUNWprivate_1.1
 end
 
@@ -4845,7 +4868,7 @@
 
 function	ucred_getasid
 include		<ucred.h>, <bsm/audit.h>
-declaration	au_asid_t ucred_getasid(const ucred_t *) 
+declaration	au_asid_t ucred_getasid(const ucred_t *)
 version		SUNWprivate_1.1
 end
 
@@ -4856,7 +4879,7 @@
 
 function	ucred_getamask
 include		<ucred.h>, <bsm/audit.h>
-declaration	const au_mask_t *ucred_getamask(const ucred_t *) 
+declaration	const au_mask_t *ucred_getamask(const ucred_t *)
 version		SUNWprivate_1.1
 end
 
@@ -4867,7 +4890,7 @@
 
 function	ucred_getatid
 include		<ucred.h>, <bsm/audit.h>
-declaration	const au_tid64_addr_t *ucred_getatid(const ucred_t *) 
+declaration	const au_tid64_addr_t *ucred_getatid(const ucred_t *)
 version		SUNWprivate_1.1
 end
 
--- a/usr/src/lib/libc/spec/interface64.spec	Thu Feb 23 04:18:08 2006 -0800
+++ b/usr/src/lib/libc/spec/interface64.spec	Thu Feb 23 04:39:12 2006 -0800
@@ -1,13 +1,12 @@
 #
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # CDDL HEADER START
 #
 # The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License").  You may not use this file except in compliance
-# with the License.
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
 #
 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 # or http://www.opensolaris.org/os/licensing.
@@ -236,6 +235,19 @@
 version		SUNW_1.1
 end
 
+function	mkstemps64
+include		<stdlib.h>
+declaration	int mkstemps64(char *template, int suffixlen)
+arch		sparc i386
+version		SUNW_1.22.1
+end
+
+function	_mkstemps64
+weak		mkstemps64
+arch		sparc i386
+version		SUNW_1.22.1
+end
+
 function	mmap64
 include		<sys/types.h>
 include		<sys/mman.h>
@@ -418,7 +430,7 @@
 version		SUNW_1.1
 end
 
-function	_statvfs64 
+function	_statvfs64
 weak		statvfs64
 arch		sparc i386
 version		SUNW_1.1
@@ -448,7 +460,7 @@
 include		<unistd.h>
 declaration	off64_t tell64(int)
 arch		sparc i386
-version		SUNW_1.1 
+version		SUNW_1.1
 end
 
 function	_tell64