#pragma prototyped
#include "dlllib.h"
extern void*
dllplugin(const char* lib, const char* name, const char* ver, unsigned long rel, unsigned long* cur, int flags, char* path, size_t size)
{
void* dll;
int err;
int hit;
Dllscan_t* dls;
Dllent_t* dle;
err = hit = 0;
for (;;)
{
if (dls = dllsopen(lib, name, ver))
{
while (dle = dllsread(dls))
{
hit = 1;
#if 0
again:
#endif
if (dll = dllopen(dle->path, flags|RTLD_GLOBAL|RTLD_PARENT))
{
if (!dllcheck(dll, dle->path, rel, cur))
{
err = state.error;
dlclose(dll);
dll = 0;
continue;
}
if (path && size)
strlcpy(path, dle->path, size);
break;
}
else
{
#if 0
char* s;
char* e;
if ((s = dllerror(1)) && (e = strchr(s, ':')))
{
*e = 0;
error(1, "AHA %s implicit", s);
dll = dllplugin(lib, s, 0, 0, 0, flags, path, size);
*e = ':';
if (dll)
{
error(1, "AHA implicit %s => %s", s, path);
goto again;
}
}
#endif
errorf("dll", NiL, 1, "dllplugin: %s dlopen failed: %s", dle->path, dllerror(1));
err = state.error;
}
}
dllsclose(dls);
}
if (hit)
{
if (!dll)
state.error = err;
return dll;
}
if (!lib)
break;
lib = 0;
}
if (dll = dllopen(name, flags))
{
if (!dllcheck(dll, name, rel, cur))
{
dlclose(dll);
dll = 0;
}
else if (path && size)
strlcpy(path, name, size);
}
return dll;
}
extern void*
dllplug(const char* lib, const char* name, const char* ver, int flags, char* path, size_t size)
{
return dllplugin(lib, name, ver, 0, NiL, flags, path, size);
}