/* * LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign * code files and libraries and locates an initialization routine */ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name, YapInitProc *init_proc) { while (ofiles) { void *handle; /* mydlopen wants to follow the LD_CONFIG_PATH */ if (!Yap_TrueFileName(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE)) { strcpy(LOCAL_ErrorSay, "%% Trying to open unexisting file in LoadForeign"); return LOAD_FAILLED; } if((handle=mydlopen(LOCAL_FileNameBuf)) == 0) { fprintf(stderr,"calling dlopen with error %s\n", mydlerror()); /* strcpy(LOCAL_ErrorSay,dlerror());*/ return LOAD_FAILLED; } ofiles->handle = handle; ofiles = ofiles->next; } /* load libraries first so that their symbols are available to other routines */ while (libs) { char *s = AtomName(lib->name); if (ls[0] == '-') { strcpy(LOCAL_FileNameBuf,"lib"); strcat(LOCAL_FileNameBuf,s+2); strcat(LOCAL_FileNameBuf,".so"); } else { strcpy(LOCAL_FileNameBuf,s); } if((libs->handle=mydlopen(LOCAL_FileNameBuf)) == NULL) { strcpy(LOCAL_ErrorSay,mydlerror()); return LOAD_FAILLED; } libs = libs->next; } *init_proc = (YapInitProc) mydlsym(proc_name); if(! *init_proc) { strcpy(LOCAL_ErrorSay,"Could not locate initialization routine"); return LOAD_FAILLED; } return LOAD_SUCCEEDED; }
static int af_ladspa_load_plugin(af_ladspa_t *setup) { const LADSPA_Descriptor *ladspa_descriptor; LADSPA_Descriptor_Function descriptor_function; int i; /* load library */ mp_msg(MSGT_AFILTER, MSGL_V, "%s: loading ladspa plugin library %s\n", setup->myname, setup->file); setup->libhandle = mydlopen(setup->file, RTLD_NOW); if (!setup->libhandle) { mp_msg(MSGT_AFILTER, MSGL_ERR, "%s: %s %s\n\t%s\n", setup->myname, MSGTR_AF_LADSPA_ErrFailedToLoad, setup->file, dlerror() ); return AF_ERROR; } mp_msg(MSGT_AFILTER, MSGL_V, "%s: library found.\n", setup->myname); /* find descriptor function */ dlerror(); descriptor_function = (LADSPA_Descriptor_Function) dlsym (setup->libhandle, "ladspa_descriptor"); if (!descriptor_function) { mp_msg(MSGT_AFILTER, MSGL_ERR, "%s: %s\n\t%s\n", setup->myname, MSGTR_AF_LADSPA_ErrNoDescriptor, dlerror()); return AF_ERROR; } /* if label == help, list all labels in library and exit */ if (strcmp(setup->label, "help") == 0) { mp_msg(MSGT_AFILTER, MSGL_INFO, "%s: %s %s:\n", setup->myname, MSGTR_AF_LADSPA_AvailableLabels, setup->file); for (i=0; ; i++) { ladspa_descriptor = descriptor_function(i); if (ladspa_descriptor == NULL) { return AF_ERROR; } mp_msg(MSGT_AFILTER, MSGL_INFO, " %-16s - %s (%lu)\n", ladspa_descriptor->Label, ladspa_descriptor->Name, ladspa_descriptor->UniqueID); } } mp_msg(MSGT_AFILTER, MSGL_V, "%s: looking for label\n", setup->myname); /* find label in library */ for (i=0; ; i++) { ladspa_descriptor = descriptor_function(i); if (ladspa_descriptor == NULL) { mp_msg(MSGT_AFILTER, MSGL_ERR, "%s: %s\n", setup->myname, MSGTR_AF_LADSPA_ErrLabelNotFound); return AF_ERROR; } if (strcmp(ladspa_descriptor->Label, setup->label) == 0) { setup->plugin_descriptor = ladspa_descriptor; mp_msg(MSGT_AFILTER, MSGL_V, "%s: %s found\n", setup->myname, setup->label); return AF_OK; } } return AF_OK; }
void * Yap_LoadForeignFile(char *file, int flags) { return (void *)mydlopen(file); }
static void* mydlopen(const char *filename, int flag) { char *buf; const char *end, *start, *ladspapath; int endsinso, needslash; size_t filenamelen; void *result = NULL; #if defined(__MINGW32__) || defined(__CYGWIN__) /* For Windows there's only absolute path support. * If you have a Windows machine, feel free to fix this. * (path separator, shared objects extension, et cetera). */ mp_msg(MSGT_AFILTER, MSGL_V, "\ton windows, only absolute pathnames " "are supported\n"); mp_msg(MSGT_AFILTER, MSGL_V, "\ttrying %s\n", filename); return dlopen(filename, flag); #endif filenamelen = strlen(filename); endsinso = 0; if (filenamelen > 3) endsinso = (strcmp(filename+filenamelen-3, ".so") == 0); if (!endsinso) { buf=malloc(filenamelen+4); strcpy(buf, filename); strcat(buf, ".so"); result=mydlopen(buf, flag); free(buf); } if (result) return result; ladspapath=getenv("LADSPA_PATH"); if (ladspapath) { start=ladspapath; while (*start != '\0') { end=start; while ( (*end != ':') && (*end != '\0') ) end++; buf=malloc(filenamelen + 2 + (end-start) ); if (end > start) strncpy(buf, start, end-start); needslash=0; if (end > start) if (*(end-1) != '/') { needslash = 1; buf[end-start] = '/'; } strcpy(buf+needslash+(end-start), filename); mp_msg(MSGT_AFILTER, MSGL_V, "\ttrying %s\n", buf); result=dlopen(buf, flag); free(buf); if (result) return result; start = end; if (*start == ':') start++; } /* end while there's still more in the path */ } /* end if there's a ladspapath */ /* last resort, just open it again, so the dlerror() message is correct */ mp_msg(MSGT_AFILTER, MSGL_V, "\ttrying %s\n", filename); return dlopen(filename,flag); }