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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * tmpfile - return a pointer to an update file that can be
34 * used for scratch. The file will automatically
35 * go away if the program using it terminates.
40 #include <sys/types.h>
49 static char seed
[] = { 'a', 'a', 'a', '\0' };
50 static mutex_t seed_lk
= DEFAULTMUTEX
;
52 #define XS "\bXXXXXX" /* a '\b' character is prepended to this */
53 /* string to avoid conflicts with names */
54 /* generated by tmpnam() */
57 _common(boolean_t large_file
)
59 char tfname
[L_tmpnam
];
65 (void) strcpy(tfname
, P_tmpdir
);
66 lmutex_lock(&seed_lk
);
67 (void) strcat(tfname
, seed
);
68 (void) strcat(tfname
, XS
);
75 lmutex_unlock(&seed_lk
);
78 if (large_file
== B_TRUE
) {
79 if ((mkret
= mkstemp64(tfname
)) == -1)
83 if ((mkret
= mkstemp(tfname
)) == -1)
86 (void) unlink(tfname
);
87 current_umask
= umask(0777);
88 (void) umask(current_umask
);
89 (void) fchmod(mkret
, 0666 & ~current_umask
);
90 if ((p
= fdopen(mkret
, "w+")) == NULL
) {
102 return (_common(B_TRUE
));
107 * This is a bit confusing -- some explanation is in order.
109 * When we're compiled 64-bit, there's no point in distinguishing
110 * a "large" file from a "small" file -- they're all "large".
111 * The argument we pass to '_common' is ignored -- we always call
112 * mkstemp which will just do the right thing for us.
117 return (_common(B_FALSE
));