xref: /titanic_52/usr/src/cmd/svr4pkg/libinst/srcpath.c (revision 9aa73b6813b3fd35e78fcc44fd17535e765e504c)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29 
30 
31 
32 #include <limits.h>
33 #include <string.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 
39 char *
40 srcpath(char *dir, char *src, int part, int nparts)
41 {
42 	static char tmppath[PATH_MAX];
43 	char	*copy;
44 	size_t	copyLen;
45 
46 	copy = tmppath;
47 
48 	if (dir != NULL) {
49 		size_t theLen = strlen(dir);
50 
51 		(void) strcpy(copy, dir);
52 		copy += theLen;
53 		copyLen = (sizeof (tmppath) - theLen);
54 	} else {
55 		copy[0] = '\0';
56 		copyLen = sizeof (tmppath);
57 	}
58 
59 	if (nparts > 1) {
60 		(void) snprintf(copy, copyLen,
61 			((src[0] == '/') ? "/root.%d%s" : "/reloc.%d/%s"),
62 			part, src);
63 	} else {
64 		(void) snprintf(copy, copyLen,
65 			((src[0] == '/') ? "/root%s" : "/reloc/%s"), src);
66 	}
67 
68 	return (tmppath);
69 }
70