Print this page
make: remove SCCS ident stuff
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/lib/vroot/src/vroot.cc
+++ new/usr/src/cmd/make/lib/vroot/src/vroot.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 -/*
26 - * @(#)vroot.cc 1.11 06/12/12
27 - */
28 25
29 -#pragma ident "@(#)vroot.cc 1.11 06/12/12"
30 26
31 27 #include <stdlib.h>
32 28 #include <string.h>
33 29
34 30 #include <vroot/vroot.h>
35 31 #include <vroot/args.h>
36 32
37 33 #include <string.h>
38 34 #include <sys/param.h>
39 35 #include <sys/file.h>
40 36
41 37 #include <avo/intl.h> /* for NOCATGETS */
42 38
43 39 typedef struct {
44 40 short init;
45 41 pathpt vector;
46 42 char *env_var;
47 43 } vroot_patht;
48 44
49 45 typedef struct {
50 46 vroot_patht vroot;
51 47 vroot_patht path;
52 48 char full_path[MAXPATHLEN+1];
53 49 char *vroot_start;
54 50 char *path_start;
55 51 char *filename_start;
56 52 int scan_vroot_first;
57 53 int cpp_style_path;
58 54 } vroot_datat, *vroot_datapt;
59 55
60 56 static vroot_datat vroot_data= {
61 57 { 0, NULL, NOCATGETS("VIRTUAL_ROOT")},
62 58 { 0, NULL, NOCATGETS("PATH")},
63 59 "", NULL, NULL, NULL, 0, 1};
64 60
65 61 void
66 62 add_dir_to_path(register char *path, register pathpt *pointer, register int position)
67 63 {
68 64 register int size= 0;
69 65 register int length;
70 66 register char *name;
71 67 register pathcellpt p;
72 68 pathpt new_path;
73 69
74 70 if (*pointer != NULL) {
75 71 for (p= &((*pointer)[0]); p->path != NULL; p++, size++);
76 72 if (position < 0)
77 73 position= size;}
78 74 else
79 75 if (position < 0)
80 76 position= 0;
81 77 if (position >= size) {
82 78 new_path= (pathpt)calloc((unsigned)(position+2), sizeof(pathcellt));
83 79 if (*pointer != NULL) {
84 80 memcpy((char *)new_path,(char *)(*pointer), size*sizeof(pathcellt));
85 81 free((char *)(*pointer));};
86 82 *pointer= new_path;};
87 83 length= strlen(path);
88 84 name= (char *)malloc((unsigned)(length+1));
89 85 (void)strcpy(name, path);
90 86 if ((*pointer)[position].path != NULL)
91 87 free((*pointer)[position].path);
92 88 (*pointer)[position].path= name;
93 89 (*pointer)[position].length= length;
94 90 }
95 91
96 92 pathpt
97 93 parse_path_string(register char *string, register int remove_slash)
98 94 {
99 95 register char *p;
100 96 pathpt result= NULL;
101 97
102 98 if (string != NULL)
103 99 for (; 1; string= p+1) {
104 100 if (p= strchr(string, ':')) *p= 0;
105 101 if ((remove_slash == 1) && !strcmp(string, "/"))
106 102 add_dir_to_path("", &result, -1);
107 103 else
108 104 add_dir_to_path(string, &result, -1);
109 105 if (p) *p= ':';
110 106 else return(result);};
111 107 return((pathpt)NULL);
112 108 }
113 109
114 110 char *
115 111 get_vroot_name(void)
116 112 {
117 113 return(vroot_data.vroot.env_var);
118 114 }
119 115
120 116 char *
121 117 get_path_name(void)
122 118 {
123 119 return(vroot_data.path.env_var);
124 120 }
125 121
126 122 void
127 123 flush_path_cache(void)
128 124 {
129 125 vroot_data.path.init= 0;
130 126 }
131 127
132 128 void
133 129 flush_vroot_cache(void)
134 130 {
135 131 vroot_data.vroot.init= 0;
136 132 }
137 133
138 134 void
139 135 scan_path_first(void)
140 136 {
141 137 vroot_data.scan_vroot_first= 0;
142 138 }
143 139
144 140 void
145 141 scan_vroot_first(void)
146 142 {
147 143 vroot_data.scan_vroot_first= 1;
148 144 }
149 145
150 146 void
151 147 set_path_style(int style)
152 148 {
153 149 vroot_data.cpp_style_path= style;
154 150 }
155 151
156 152 char *
157 153 get_vroot_path(register char **vroot, register char **path, register char **filename)
158 154 {
159 155 if (vroot != NULL) {
160 156 if ((*vroot= vroot_data.vroot_start) == NULL)
161 157 if ((*vroot= vroot_data.path_start) == NULL)
162 158 *vroot= vroot_data.filename_start;};
163 159 if (path != NULL) {
164 160 if ((*path= vroot_data.path_start) == NULL)
165 161 *path= vroot_data.filename_start;};
166 162 if (filename != NULL)
167 163 *filename= vroot_data.filename_start;
168 164 return(vroot_data.full_path);
169 165 }
170 166
171 167 void
172 168 translate_with_thunk(register char *filename, int (*thunk) (char *), pathpt path_vector, pathpt vroot_vector, rwt rw)
173 169 {
174 170 register pathcellt *vp;
175 171 pathcellt *pp;
176 172 register pathcellt *pp1;
177 173 register char *p;
178 174 int flags[256];
179 175
180 176 /* Setup path to use */
181 177 if (rw == rw_write)
182 178 pp1= NULL; /* Do not use path when writing */
183 179 else {
184 180 if (path_vector == VROOT_DEFAULT) {
185 181 if (!vroot_data.path.init) {
186 182 vroot_data.path.init= 1;
187 183 vroot_data.path.vector= parse_path_string(getenv(vroot_data.path.env_var), 0);};
188 184 path_vector= vroot_data.path.vector;};
189 185 pp1= path_vector == NULL ? NULL : &(path_vector)[0];};
190 186
191 187 /* Setup vroot to use */
192 188 if (vroot_vector == VROOT_DEFAULT) {
193 189 if (!vroot_data.vroot.init) {
194 190 vroot_data.vroot.init= 1;
195 191 vroot_data.vroot.vector= parse_path_string(getenv(vroot_data.vroot.env_var), 1);};
196 192 vroot_vector= vroot_data.vroot.vector;};
197 193 vp= vroot_vector == NULL ? NULL : &(vroot_vector)[0];
198 194
199 195 /* Setup to remember pieces */
200 196 vroot_data.vroot_start= NULL;
201 197 vroot_data.path_start= NULL;
202 198 vroot_data.filename_start= NULL;
203 199
204 200 int flen = strlen(filename);
205 201 if(flen >= MAXPATHLEN) {
206 202 errno = ENAMETOOLONG;
207 203 return;
208 204 }
209 205
210 206 switch ((vp ?1:0) + (pp1 ? 2:0)) {
211 207 case 0: /* No path. No vroot. */
212 208 use_name:
213 209 (void)strcpy(vroot_data.full_path, filename);
214 210 vroot_data.filename_start= vroot_data.full_path;
215 211 (void)(*thunk)(vroot_data.full_path);
216 212 return;
217 213 case 1: /* No path. Vroot */
218 214 if (filename[0] != '/') goto use_name;
219 215 for (; vp->path != NULL; vp++) {
220 216 if((1 + flen + vp->length) >= MAXPATHLEN) {
221 217 errno = ENAMETOOLONG;
222 218 continue;
223 219 }
224 220 p= vroot_data.full_path;
225 221 (void)strcpy(vroot_data.vroot_start= p, vp->path);
226 222 p+= vp->length;
227 223 (void)strcpy(vroot_data.filename_start= p, filename);
228 224 if ((*thunk)(vroot_data.full_path)) return;};
229 225 (void)strcpy(vroot_data.full_path, filename);
230 226 return;
231 227 case 2: /* Path. No vroot. */
232 228 if (vroot_data.cpp_style_path) {
233 229 if (filename[0] == '/') goto use_name;
234 230 } else {
235 231 if (strchr(filename, '/') != NULL) goto use_name;
236 232 };
237 233 for (; pp1->path != NULL; pp1++) {
238 234 p= vroot_data.full_path;
239 235 if((1 + flen + pp1->length) >= MAXPATHLEN) {
240 236 errno = ENAMETOOLONG;
241 237 continue;
242 238 }
243 239 if (vroot_data.cpp_style_path) {
244 240 (void)strcpy(vroot_data.path_start= p, pp1->path);
245 241 p+= pp1->length;
246 242 *p++= '/';
247 243 } else {
248 244 if (pp1->length != 0) {
249 245 (void)strcpy(vroot_data.path_start= p,
250 246 pp1->path);
251 247 p+= pp1->length;
252 248 *p++= '/';
253 249 };
254 250 };
255 251 (void)strcpy(vroot_data.filename_start= p, filename);
256 252 if ((*thunk)(vroot_data.full_path)) return;};
257 253 (void)strcpy(vroot_data.full_path, filename);
258 254 return;
259 255 case 3: { /* Path. Vroot. */
260 256 int *rel_path, path_len= 1;
261 257 if (vroot_data.scan_vroot_first == 0) {
262 258 for (pp= pp1; pp->path != NULL; pp++) path_len++;
263 259 rel_path= flags;
264 260 for (path_len-= 2; path_len >= 0; path_len--) rel_path[path_len]= 0;
265 261 for (; vp->path != NULL; vp++)
266 262 for (pp= pp1, path_len= 0; pp->path != NULL; pp++, path_len++) {
267 263 int len = 0;
268 264 if (rel_path[path_len] == 1) continue;
269 265 if (pp->path[0] != '/') rel_path[path_len]= 1;
270 266 p= vroot_data.full_path;
271 267 if ((filename[0] == '/') || (pp->path[0] == '/')) {
272 268 if(vp->length >= MAXPATHLEN) {
273 269 errno = ENAMETOOLONG;
274 270 continue;
275 271 }
276 272 (void)strcpy(vroot_data.vroot_start= p, vp->path); p+= vp->length;
277 273 len += vp->length;
278 274 };
279 275 if (vroot_data.cpp_style_path) {
280 276 if (filename[0] != '/') {
281 277 if(1 + len + pp->length >= MAXPATHLEN) {
282 278 errno = ENAMETOOLONG;
283 279 continue;
284 280 }
285 281 (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
286 282 *p++= '/';
287 283 len += 1 + pp->length;
288 284 };
289 285 } else {
290 286 if (strchr(filename, '/') == NULL) {
291 287 if (pp->length != 0) {
292 288 if(1 + len + pp->length >= MAXPATHLEN) {
293 289 errno = ENAMETOOLONG;
294 290 continue;
295 291 }
296 292 (void)strcpy(vroot_data.path_start= p,
297 293 pp->path);
298 294 p+= pp->length;
299 295 *p++= '/';
300 296 len += 1 + pp->length;
301 297 }
302 298 }
303 299 };
304 300 (void)strcpy(vroot_data.filename_start= p, filename);
305 301 if ((*thunk)(vroot_data.full_path)) return;};}
306 302 else { pathcellt *vp1= vp;
307 303 for (pp= pp1, path_len= 0; pp->path != NULL; pp++, path_len++)
308 304 for (vp= vp1; vp->path != NULL; vp++) {
309 305 int len = 0;
310 306 p= vroot_data.full_path;
311 307 if ((filename[0] == '/') || (pp->path[0] == '/')) {
312 308 if(vp->length >= MAXPATHLEN) {
313 309 errno = ENAMETOOLONG;
314 310 continue;
315 311 }
316 312 (void)strcpy(vroot_data.vroot_start= p, vp->path); p+= vp->length;
317 313 len += vp->length;
318 314 }
319 315 if (vroot_data.cpp_style_path) {
320 316 if (filename[0] != '/') {
321 317 if(1 + len + pp->length >= MAXPATHLEN) {
322 318 errno = ENAMETOOLONG;
323 319 continue;
324 320 }
325 321 (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
326 322 *p++= '/';
327 323 len += 1 + pp->length;
328 324 }
329 325 } else {
330 326 if (strchr(filename, '/') == NULL) {
331 327 if(1 + len + pp->length >= MAXPATHLEN) {
332 328 errno = ENAMETOOLONG;
333 329 continue;
334 330 }
335 331 (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
336 332 *p++= '/';
337 333 len += 1 + pp->length;
338 334 }
339 335 }
340 336 (void)strcpy(vroot_data.filename_start= p, filename);
341 337 if ((*thunk)(vroot_data.full_path)) return;};};
342 338 (void)strcpy(vroot_data.full_path, filename);
343 339 return;};};
344 340 }
↓ open down ↓ |
305 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX