10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER START
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The contents of this file are subject to the terms of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Common Development and Distribution License (the "License").
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You may not use this file except in compliance with the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * See the License for the specific language governing permissions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and limitations under the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If applicable, add the following below this CDDL HEADER, with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER END
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef struct {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetypedef struct {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweadd_dir_to_path(const char *path, register pathpt *pointer, register int position)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (p= &((*pointer)[0]); p->path != NULL; p++, size++);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe new_path= (pathpt)calloc((unsigned)(position+2), sizeof(pathcellt));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe memcpy((char *)new_path,(char *)(*pointer), size*sizeof(pathcellt));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweparse_path_string(register char *string, register int remove_slash)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register char *p;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((remove_slash == 1) && !strcmp(string, "/"))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (p) *p= ':';
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else return(result);};
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweget_vroot_path(register char **vroot, register char **path, register char **filename)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowetranslate_with_thunk(register char *filename, int (*thunk) (char *), pathpt path_vector, pathpt vroot_vector, rwt rw)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register char *p;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Setup path to use */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe vroot_data.path.vector= parse_path_string(getenv(vroot_data.path.env_var), 0);};
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pp1= path_vector == NULL ? NULL : &(path_vector)[0];};
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Setup vroot to use */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe vroot_data.vroot.vector= parse_path_string(getenv(vroot_data.vroot.env_var), 1);};
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe vp= vroot_vector == NULL ? NULL : &(vroot_vector)[0];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Setup to remember pieces */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case 0: /* No path. No vroot. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe vroot_data.filename_start= vroot_data.full_path;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.vroot_start= p, vp->path);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.filename_start= p, filename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (strchr(filename, '/') != NULL) goto use_name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.path_start= p, pp1->path);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.filename_start= p, filename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pp= pp1; pp->path != NULL; pp++) path_len++;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (path_len-= 2; path_len >= 0; path_len--) rel_path[path_len]= 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pp= pp1, path_len= 0; pp->path != NULL; pp++, path_len++) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((filename[0] == '/') || (pp->path[0] == '/')) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.vroot_start= p, vp->path); p+= vp->length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.filename_start= p, filename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pp= pp1, path_len= 0; pp->path != NULL; pp++, path_len++)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((filename[0] == '/') || (pp->path[0] == '/')) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.vroot_start= p, vp->path); p+= vp->length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void)strcpy(vroot_data.filename_start= p, filename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((*thunk)(vroot_data.full_path)) return;};};