4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */
36 #define max(A,B) (((A)<(B))?(B):(A))
38 extern char *malloc(), *getenv(), *mktemp();
46 char *dir
; /* use this directory please (if non-NULL) */
47 char *pfx
; /* use this (if non-NULL) as filename prefix */
49 register char *p
, *q
, *tdir
;
53 seed
[0] = seed
[1] = seed
[2] = 'A';
55 if((tdir
= getenv("TMPDIR")) != NULL
) {
61 if((p
=malloc((unsigned)(max(max(x
,y
),z
)+16))) == NULL
)
63 if(x
> 0 && access(pcopy(p
, tdir
), 3) == 0)
65 if(y
> 0 && access(pcopy(p
, dir
), 3) == 0)
67 if(access(pcopy(p
, P_tmpdir
), 3) == 0)
69 if(access(pcopy(p
, "/tmp"), 3) != 0)
74 *(p
+strlen(p
)+5) = '\0';
75 (void)strncat(p
, pfx
, 5);
77 (void)strcat(p
, seed
);
78 (void)strcat(p
, "XXXXXX");
83 if(*mktemp(p
) == '\0')
95 (void)strcpy(space
, arg
);
96 p
= space
-1+strlen(space
);