1 /***************************************************************************
2 kdbloader.c - Dynamically loading backends
4 begin : Sun Mar 19 2006
5 copyright : (C) 2004 by Avi Alkalay
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the BSD License (revised). *
14 ***************************************************************************/
25 #include "kdbloader.h"
35 kdbLibHandle kdbLibLoad(const char *module)
37 kdblib_symbol *current;
38 current = kdb_exported_syms;
39 while ( current->name != NULL ) {
40 /* Skip symbols, we're searching for
42 if ( current->function == NULL && strcmp(current->name, module) == 0 ) {
43 /* Go to the first symbol for this file */
54 kdbLibFunc kdbLibSym(kdbLibHandle handle, const char *symbol)
56 kdblib_symbol *current;
59 /* For each symbol about this module */
60 while ( current->function != NULL ) {
61 if ( strcmp(current->name, symbol) == 0 )
62 return current->function;
70 int kdbLibClose(kdbLibHandle handle)
77 /* Windows dynamic case */
84 kdbLibHandle kdbLibLoad(const char *module)
86 char *modulename = malloc((sizeof(char)*strlen(module))+sizeof(".dll"));
88 strcpy(modulename, module);
89 strcat(modulename, ".dll");
90 handle = LoadLibrary(modulename);
95 kdbLibFunc kdbLibSym(kdbLibHandle handle, const char *symbol)
97 return GetProcAddress(handle, symbol);
100 int kdbLibClose(kdbLibHandle handle)
102 return FreeLibrary(handle);
106 /* Generic case using libltdl */
110 init_errors = lt_dlinit();
113 return lt_dladdsearchdir(BACKEND_LIBDIR);
116 kdbLibHandle kdbLibLoad(const char *module)
119 handle = lt_dlopenext(module);
123 kdbLibFunc kdbLibSym(kdbLibHandle handle, const char *symbol)
125 return (kdbLibFunc) lt_dlsym(handle, symbol);
128 int kdbLibClose(kdbLibHandle handle)
130 return lt_dlclose(handle);