4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Create unique plain files or directories.
28 #pragma ident "%Z%%M% %I% %E% SMI"
39 (void) fprintf(stderr
,
40 gettext("Usage: mktemp [-dqtu] [-p prefix_dir] [template]\n"));
46 main(int argc
, char **argv
)
50 boolean_t dounlink
= B_FALSE
;
51 boolean_t domkdir
= B_FALSE
;
52 boolean_t quiet
= B_FALSE
;
53 boolean_t usetmpdir
= B_FALSE
;
54 char template[] = "tmp.XXXXXX";
57 (void) setlocale(LC_ALL
, "");
60 #define TEXT_DOMAIN "SYS_TEST"
62 (void) textdomain(TEXT_DOMAIN
);
66 while ((opt
= getopt(argc
, argv
, "dqtup:")) != EOF
) {
76 /* FALLTHROUGH - -p implies -t */
102 char *tmp
= getenv("TMPDIR");
105 if (strchr(tmpl
, '/') != NULL
) {
106 (void) fprintf(stderr
,
107 gettext("mktemp: template argument specified "
108 "with -t/-p option must not contain '/'"
112 /* TMPDIR overrides -p so that scripts will honor $TMPDIR */
115 else if (prefix
== NULL
)
118 len
= snprintf(NULL
, 0, "%s/%s", prefix
, tmpl
) + 1;
124 (void) snprintf(tmp
, len
, "%s/%s", prefix
, tmpl
);
129 if (mkdtemp(tmpl
) == NULL
) {
131 (void) fprintf(stderr
,
132 gettext("mktemp: failed to create "
133 "directory: %s\n"), tmpl
);
140 if (mkstemp(tmpl
) < 0) {
142 (void) fprintf(stderr
,
143 gettext("mktemp: failed to create file: "