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 (c) 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
25 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
30 * Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
33 * Portions of this source code were derived from Berkeley
34 * 4.3 BSD under license from the regents of the University of
38 #include <sys/feature_tests.h>
40 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
41 #define mkstemp mkstemp64
42 #define mkstemps mkstemps64
43 #define mkostemp mkostemp64
44 #define mkostemps mkostemps64
45 #define libc_mkstemps libc_mkstemps64 /* prefer unique statics */
46 #pragma weak _mkstemp64 = mkstemp64
48 #pragma weak _mkstemp = mkstemp
52 #include <sys/fcntl.h>
57 #include <sys/types.h>
61 extern char *libc_mktemps(char *, int);
64 libc_mkstemps(char *as
, int slen
, int flags
)
68 char *tstr
, *str
, *mkret
;
70 if (as
== NULL
|| *as
== NULL
)
73 len
= (int)strlen(as
);
74 tstr
= alloca(len
+ 1);
75 (void) strcpy(tstr
, as
);
77 if (slen
< 0 || slen
>= len
)
80 str
= tstr
+ (len
- 1 - slen
);
83 * The following for() loop is doing work. mktemp() will generate
84 * a different name each time through the loop. So if the first
85 * name is used then keep trying until you find a free filename.
89 if (*str
== 'X') { /* If no trailing X's don't call mktemp. */
90 mkret
= libc_mktemps(as
, slen
);
95 #if _FILE_OFFSET_BITS == 64
96 if ((fd
= open64(as
, O_CREAT
|O_EXCL
|O_RDWR
|flags
,
101 if ((fd
= open(as
, O_CREAT
|O_EXCL
|O_RDWR
|flags
,
105 #endif /* _FILE_OFFSET_BITS == 64 */
108 * If the error condition is other than EEXIST or if the
109 * file exists and there are no X's in the string
113 if ((errno
!= EEXIST
) || (*str
!= 'X')) {
116 (void) strcpy(as
, tstr
);
123 return (libc_mkstemps(as
, 0, 0));
127 mkstemps(char *as
, int slen
)
129 return (libc_mkstemps(as
, slen
, 0));
133 mkostemp(char *as
, int flags
)
135 return (libc_mkstemps(as
, 0, flags
));
139 mkostemps(char *as
, int slen
, int flags
)
141 return (libc_mkstemps(as
, slen
, flags
));