/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1997-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#pragma prototyped20/*21* Glenn Fowler22* at&t research23*/2425#include "dlllib.h"2627#if 02829/*30* dlopen() wrapper that properly initializes LIBPATH31* with the path of the dll to be opened32*33* 2009-04-15 -- if ld.so re-checked the env this would work ...34*/3536void*37dllopen(const char* name, int mode)38{39void* dll;40Dllinfo_t* info;41char* olibpath;42char* path;43char* oenv;44char* nenv[2];45char* dir;46char* base;47int len;4849if (!environ)50{51nenv[0] = nenv[1] = 0;52environ = nenv;53}54info = dllinfo();55oenv = environ[0];56olibpath = getenv(info->env);57if (base = strrchr(name, '/'))58{59dir = (char*)name;60len = ++base - dir;61}62else63{64dir = "./";65len = 2;66base = (char*)name;67}68path = sfprints("%-.*s%s%c%s=%-.*s%s%s", len, dir, base, 0, info->env, len, dir, olibpath ? ":" : "", olibpath ? olibpath : "");69environ[0] = path + strlen(path) + 1;70state.error = 0;71dll = dlopen(path, mode);72if (environ == nenv)73environ = 0;74else75environ[0] = oenv;76return dll;77}7879#else8081/*82* dlopen() wrapper -- waiting for prestidigitaions83*/8485void*86dllopen(const char* name, int mode)87{88state.error = 0;89return dlopen(name, mode);90}9192#endif939495