diff options
Diffstat (limited to 'usr/src/cmd/mktemp')
| -rw-r--r-- | usr/src/cmd/mktemp/mktemp.c | 43 |
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 " |
