xref: /titanic_44/usr/src/lib/libdll/common/dllopen.c (revision c5a5e6f47e8f40ef4f4a14b199b09585e3ecf9a0)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1997-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22  * Glenn Fowler
23  * at&t research
24  */
25 
26 #include <ast.h>
27 #include <dlldefs.h>
28 #include <error.h>
29 
30 #if 0
31 
32 /*
33  * dlopen() wrapper that properly initializes LIBPATH
34  * with the path of the dll to be opened
35  *
36  * 2009-04-15 -- if ld.so re-checked the env this would work ...
37  */
38 
39 void*
40 dllopen(const char* name, int mode)
41 {
42 	void*		dll;
43 	Dllinfo_t*	info;
44 	char*		olibpath;
45 	char*		path;
46 	char*		oenv;
47 	char*		nenv[2];
48 	char*		dir;
49 	char*		base;
50 	int		len;
51 
52 	if (!environ)
53 	{
54 		nenv[0] = nenv[1] = 0;
55 		environ = nenv;
56 	}
57 	info = dllinfo();
58 	oenv = environ[0];
59 	olibpath = getenv(info->env);
60 	if (base = strrchr(name, '/'))
61 	{
62 		dir = (char*)name;
63 		len = ++base - dir;
64 	}
65 	else
66 	{
67 		dir = "./";
68 		len = 2;
69 		base = (char*)name;
70 	}
71 	path = sfprints("%-.*s%s%c%s=%-.*s%s%s", len, dir, base, 0, info->env, len, dir, olibpath ? ":" : "", olibpath ? olibpath : "");
72 	environ[0] = path + strlen(path) + 1;
73 	dll = dlopen(path, mode);
74 	if (environ == nenv)
75 		environ = 0;
76 	else
77 		environ[0] = oenv;
78 	return dll;
79 }
80 
81 #else
82 
83 /*
84  * dlopen() wrapper -- waiting for prestidigitaions
85  */
86 
87 void*
88 dllopen(const char* name, int mode)
89 {
90 	return dlopen(name, mode);
91 }
92 
93 #endif
94