1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1997-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
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 "dlllib.h"
27 
28 #if 0
29 
30 /*
31  * dlopen() wrapper that properly initializes LIBPATH
32  * with the path of the dll to be opened
33  *
34  * 2009-04-15 -- if ld.so re-checked the env this would work ...
35  */
36 
37 void*
38 dllopen(const char* name, int mode)
39 {
40 	void*		dll;
41 	Dllinfo_t*	info;
42 	char*		olibpath;
43 	char*		path;
44 	char*		oenv;
45 	char*		nenv[2];
46 	char*		dir;
47 	char*		base;
48 	int		len;
49 
50 	if (!environ)
51 	{
52 		nenv[0] = nenv[1] = 0;
53 		environ = nenv;
54 	}
55 	info = dllinfo();
56 	oenv = environ[0];
57 	olibpath = getenv(info->env);
58 	if (base = strrchr(name, '/'))
59 	{
60 		dir = (char*)name;
61 		len = ++base - dir;
62 	}
63 	else
64 	{
65 		dir = "./";
66 		len = 2;
67 		base = (char*)name;
68 	}
69 	path = sfprints("%-.*s%s%c%s=%-.*s%s%s", len, dir, base, 0, info->env, len, dir, olibpath ? ":" : "", olibpath ? olibpath : "");
70 	environ[0] = path + strlen(path) + 1;
71 	state.error = 0;
72 	dll = dlopen(path, mode);
73 	if (environ == nenv)
74 		environ = 0;
75 	else
76 		environ[0] = oenv;
77 	return dll;
78 }
79 
80 #else
81 
82 /*
83  * dlopen() wrapper -- waiting for prestidigitaions
84  */
85 
86 void*
dllopen(const char * name,int mode)87 dllopen(const char* name, int mode)
88 {
89 	state.error = 0;
90 	return dlopen(name, mode);
91 }
92 
93 #endif
94