summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mktemp
diff options
context:
space:
mode:
authorcasper <none@none>2006-02-23 04:39:12 -0800
committercasper <none@none>2006-02-23 04:39:12 -0800
commit7c4dcc5546f9f002dfc2b95de47c90f00d07c066 (patch)
tree7e3a6d7a854319ac7ab26d01c3bb2f5bcefe59be /usr/src/cmd/mktemp
parenta07094369b21309434206d9b3601d162693466fc (diff)
downloadillumos-joyent-7c4dcc5546f9f002dfc2b95de47c90f00d07c066.tar.gz
PSARC/2006/107 mkstemps(3C)/mkdtemp(3C)
6386057 Add mkdtemp(3C)/mkstemps(3C)
Diffstat (limited to 'usr/src/cmd/mktemp')
-rw-r--r--usr/src/cmd/mktemp/mktemp.c43
1 files changed, 4 insertions, 39 deletions
diff --git a/usr/src/cmd/mktemp/mktemp.c b/usr/src/cmd/mktemp/mktemp.c
index d7982b892b..93d5338ae2 100644
--- a/usr/src/cmd/mktemp/mktemp.c
+++ b/usr/src/cmd/mktemp/mktemp.c
@@ -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 @@ usage(void)
/* 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 @@ main(int argc, char **argv)
}
if (domkdir) {
- if (mktmpdir(tmpl) != 0) {
+ if (mkdtemp(tmpl) == NULL) {
if (!quiet) {
(void) fprintf(stderr,
gettext("mktemp: failed to create "