00001 /** \file osLinux.c 00002 00003 \brief Linux specific code 00004 00005 ******************************************************************************/ 00006 00007 #include "os.h" 00008 #include "dlfcn.h" // for dynamic linkage: dlopen, etc. 00009 00010 /**AutomaticStart*************************************************************/ 00011 00012 /*---------------------------------------------------------------------------*/ 00013 /* Static function prototypes */ 00014 /*---------------------------------------------------------------------------*/ 00015 00016 static void do_one_thing (void *arg_in); 00017 00018 /**AutomaticEnd***************************************************************/ 00019 00020 00021 00022 /** 00023 * \brief Take a function name and the name of the library that 00024 * implements it, and dynamically map in that functions code. 00025 * Add a map from the function name to the actual function. 00026 */ 00027 00028 void 00029 Os_DynamicallyLinkFunction (st_table * nameToFunction, 00030 char *aName, char *library) 00031 { 00032 // based on manpage for dlopen 00033 void *handle; 00034 void (*aFunction) (); 00035 char *error; 00036 00037 // ... Optionally, RTLD_GLOBAL may be or’ed with flag, in which case 00038 // the external symbols defined in the library will be made available to 00039 // subsequently loaded libraries. 00040 handle = dlopen (library, RTLD_NOW | RTLD_GLOBAL); 00041 if (handle == NULL) 00042 { 00043 printf ("%s\n", dlerror ()); 00044 assert (0); 00045 } 00046 00047 aFunction = ( void (*)() ) dlsym (handle, aName); 00048 if ((error = dlerror ()) != NULL) 00049 { 00050 fprintf (stderr, "%s\n", error); 00051 assert (0); 00052 } 00053 if (nameToFunction != NIL (st_table)) 00054 { 00055 Hash_Insert (nameToFunction, aName, (char *) aFunction); 00056 } 00057 }