xref: /titanic_50/usr/src/lib/libdll/common/dllopen.c (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
134f9b3eeSRoland Mainz /***********************************************************************
234f9b3eeSRoland Mainz *                                                                      *
334f9b3eeSRoland Mainz *               This software is part of the ast package               *
4*3e14f97fSRoger A. Faulkner *          Copyright (c) 1997-2010 AT&T Intellectual Property          *
534f9b3eeSRoland Mainz *                      and is licensed under the                       *
634f9b3eeSRoland Mainz *                  Common Public License, Version 1.0                  *
734f9b3eeSRoland Mainz *                    by AT&T Intellectual Property                     *
834f9b3eeSRoland Mainz *                                                                      *
934f9b3eeSRoland Mainz *                A copy of the License is available at                 *
1034f9b3eeSRoland Mainz *            http://www.opensource.org/licenses/cpl1.0.txt             *
1134f9b3eeSRoland Mainz *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
1234f9b3eeSRoland Mainz *                                                                      *
1334f9b3eeSRoland Mainz *              Information and Software Systems Research               *
1434f9b3eeSRoland Mainz *                            AT&T Research                             *
1534f9b3eeSRoland Mainz *                           Florham Park NJ                            *
1634f9b3eeSRoland Mainz *                                                                      *
1734f9b3eeSRoland Mainz *                 Glenn Fowler <gsf@research.att.com>                  *
1834f9b3eeSRoland Mainz *                                                                      *
1934f9b3eeSRoland Mainz ***********************************************************************/
2034f9b3eeSRoland Mainz #pragma prototyped
2134f9b3eeSRoland Mainz /*
2234f9b3eeSRoland Mainz  * Glenn Fowler
2334f9b3eeSRoland Mainz  * at&t research
2434f9b3eeSRoland Mainz  */
2534f9b3eeSRoland Mainz 
2634f9b3eeSRoland Mainz #include <ast.h>
2734f9b3eeSRoland Mainz #include <dlldefs.h>
2834f9b3eeSRoland Mainz #include <error.h>
2934f9b3eeSRoland Mainz 
3034f9b3eeSRoland Mainz #if 0
3134f9b3eeSRoland Mainz 
3234f9b3eeSRoland Mainz /*
3334f9b3eeSRoland Mainz  * dlopen() wrapper that properly initializes LIBPATH
3434f9b3eeSRoland Mainz  * with the path of the dll to be opened
3534f9b3eeSRoland Mainz  *
3634f9b3eeSRoland Mainz  * 2009-04-15 -- if ld.so re-checked the env this would work ...
3734f9b3eeSRoland Mainz  */
3834f9b3eeSRoland Mainz 
3934f9b3eeSRoland Mainz void*
4034f9b3eeSRoland Mainz dllopen(const char* name, int mode)
4134f9b3eeSRoland Mainz {
4234f9b3eeSRoland Mainz 	void*		dll;
4334f9b3eeSRoland Mainz 	Dllinfo_t*	info;
4434f9b3eeSRoland Mainz 	char*		olibpath;
4534f9b3eeSRoland Mainz 	char*		path;
4634f9b3eeSRoland Mainz 	char*		oenv;
4734f9b3eeSRoland Mainz 	char*		nenv[2];
4834f9b3eeSRoland Mainz 	char*		dir;
4934f9b3eeSRoland Mainz 	char*		base;
5034f9b3eeSRoland Mainz 	int		len;
5134f9b3eeSRoland Mainz 
5234f9b3eeSRoland Mainz 	if (!environ)
5334f9b3eeSRoland Mainz 	{
5434f9b3eeSRoland Mainz 		nenv[0] = nenv[1] = 0;
5534f9b3eeSRoland Mainz 		environ = nenv;
5634f9b3eeSRoland Mainz 	}
5734f9b3eeSRoland Mainz 	info = dllinfo();
5834f9b3eeSRoland Mainz 	oenv = environ[0];
5934f9b3eeSRoland Mainz 	olibpath = getenv(info->env);
6034f9b3eeSRoland Mainz 	if (base = strrchr(name, '/'))
6134f9b3eeSRoland Mainz 	{
6234f9b3eeSRoland Mainz 		dir = (char*)name;
6334f9b3eeSRoland Mainz 		len = ++base - dir;
6434f9b3eeSRoland Mainz 	}
6534f9b3eeSRoland Mainz 	else
6634f9b3eeSRoland Mainz 	{
6734f9b3eeSRoland Mainz 		dir = "./";
6834f9b3eeSRoland Mainz 		len = 2;
6934f9b3eeSRoland Mainz 		base = (char*)name;
7034f9b3eeSRoland Mainz 	}
7134f9b3eeSRoland Mainz 	path = sfprints("%-.*s%s%c%s=%-.*s%s%s", len, dir, base, 0, info->env, len, dir, olibpath ? ":" : "", olibpath ? olibpath : "");
7234f9b3eeSRoland Mainz 	environ[0] = path + strlen(path) + 1;
7334f9b3eeSRoland Mainz 	dll = dlopen(path, mode);
7434f9b3eeSRoland Mainz 	if (environ == nenv)
7534f9b3eeSRoland Mainz 		environ = 0;
7634f9b3eeSRoland Mainz 	else
7734f9b3eeSRoland Mainz 		environ[0] = oenv;
7834f9b3eeSRoland Mainz 	return dll;
7934f9b3eeSRoland Mainz }
8034f9b3eeSRoland Mainz 
8134f9b3eeSRoland Mainz #else
8234f9b3eeSRoland Mainz 
8334f9b3eeSRoland Mainz /*
8434f9b3eeSRoland Mainz  * dlopen() wrapper -- waiting for prestidigitaions
8534f9b3eeSRoland Mainz  */
8634f9b3eeSRoland Mainz 
8734f9b3eeSRoland Mainz void*
dllopen(const char * name,int mode)8834f9b3eeSRoland Mainz dllopen(const char* name, int mode)
8934f9b3eeSRoland Mainz {
9034f9b3eeSRoland Mainz 	return dlopen(name, mode);
9134f9b3eeSRoland Mainz }
9234f9b3eeSRoland Mainz 
9334f9b3eeSRoland Mainz #endif
94