17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*20c1c355SRod Evans * Common Development and Distribution License (the "License").
6*20c1c355SRod Evans * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*20c1c355SRod Evans
227c478bd9Sstevel@tonic-gate /*
23*20c1c355SRod Evans * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate #include <stdlib.h>
267c478bd9Sstevel@tonic-gate #include <string.h>
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <env.h>
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate static const char *token = ":";
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate void
build_env_list(Elist ** list,const char * env)347c478bd9Sstevel@tonic-gate build_env_list(Elist **list, const char *env)
357c478bd9Sstevel@tonic-gate {
367c478bd9Sstevel@tonic-gate char *envstr;
377c478bd9Sstevel@tonic-gate char *tok;
387c478bd9Sstevel@tonic-gate char *lasts;
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate if ((envstr = getenv(env)) == NULL)
417c478bd9Sstevel@tonic-gate return;
427c478bd9Sstevel@tonic-gate envstr = strdup(envstr);
437c478bd9Sstevel@tonic-gate tok = strtok_r(envstr, token, &lasts);
447c478bd9Sstevel@tonic-gate while (tok) {
457c478bd9Sstevel@tonic-gate Elist *lp;
46*20c1c355SRod Evans if ((lp = (Elist *)malloc(sizeof (Elist))) == NULL) {
477c478bd9Sstevel@tonic-gate (void) printf("build_list: malloc failed\n");
487c478bd9Sstevel@tonic-gate exit(1);
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate lp->l_libname = strdup(tok);
517c478bd9Sstevel@tonic-gate lp->l_next = *list;
527c478bd9Sstevel@tonic-gate *list = lp;
537c478bd9Sstevel@tonic-gate tok = strtok_r(NULL, token, &lasts);
547c478bd9Sstevel@tonic-gate }
557c478bd9Sstevel@tonic-gate free(envstr);
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate Elist *
check_list(Elist * list,const char * str)607c478bd9Sstevel@tonic-gate check_list(Elist *list, const char *str)
617c478bd9Sstevel@tonic-gate {
627c478bd9Sstevel@tonic-gate const char *basestr;
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate if (list == NULL)
657c478bd9Sstevel@tonic-gate return (NULL);
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate * Is this a basename or a relative path name
697c478bd9Sstevel@tonic-gate */
70*20c1c355SRod Evans if ((basestr = strrchr(str, '/')) != NULL)
717c478bd9Sstevel@tonic-gate basestr++;
727c478bd9Sstevel@tonic-gate else
737c478bd9Sstevel@tonic-gate basestr = str;
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate for (; list; list = list->l_next) {
77*20c1c355SRod Evans if (strchr(list->l_libname, '/') == NULL) {
787c478bd9Sstevel@tonic-gate if (strcmp(basestr, list->l_libname) == 0)
797c478bd9Sstevel@tonic-gate return (list);
807c478bd9Sstevel@tonic-gate } else {
817c478bd9Sstevel@tonic-gate if (strcmp(str, list->l_libname) == 0)
827c478bd9Sstevel@tonic-gate return (list);
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate return (NULL);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate char *
checkenv(const char * env)897c478bd9Sstevel@tonic-gate checkenv(const char *env)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate char *envstr;
927c478bd9Sstevel@tonic-gate if ((envstr = getenv(env)) == NULL)
937c478bd9Sstevel@tonic-gate return (NULL);
947c478bd9Sstevel@tonic-gate while (*envstr == ' ')
957c478bd9Sstevel@tonic-gate envstr++;
967c478bd9Sstevel@tonic-gate if (*envstr == '\0')
977c478bd9Sstevel@tonic-gate return (NULL);
987c478bd9Sstevel@tonic-gate return (envstr);
997c478bd9Sstevel@tonic-gate }
100