comparison gtk/dw.c @ 157:a07dd2e819f3

Added module support.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 12 Nov 2002 08:52:22 +0000
parents 840c54766306
children df59a3fc6de6
comparison
equal deleted inserted replaced
156:63258b34e70d 157:a07dd2e819f3
4963 DW_MUTEX_LOCK; 4963 DW_MUTEX_LOCK;
4964 gdk_beep(); 4964 gdk_beep();
4965 DW_MUTEX_UNLOCK; 4965 DW_MUTEX_UNLOCK;
4966 } 4966 }
4967 4967
4968 void _my_strlwr(char *buf)
4969 {
4970 int z, len = strlen(buf);
4971
4972 for(z=0;z<len;z++)
4973 {
4974 if(buf[z] >= 'A' && buf[z] <= 'Z')
4975 buf[z] -= 'A' - 'a';
4976 }
4977 }
4978
4979 /* Open a shared library and return a handle.
4980 * Parameters:
4981 * name: Base name of the shared library.
4982 * handle: Pointer to a module handle,
4983 * will be filled in with the handle.
4984 */
4985 int dw_module_load(char *name, HMOD *handle)
4986 {
4987 int len;
4988 char *newname;
4989 char errorbuf[1024];
4990
4991
4992 if(!handle)
4993 return -1;
4994
4995 if((len = strlen(name)) == 0)
4996 return -1;
4997
4998 /* Lenth + "lib" + ".so" + NULL */
4999 newname = malloc(len + 7);
5000
5001 if(!newname)
5002 return -1;
5003
5004 sprintf(newname, "lib%s.so", name);
5005 _my_strlwr(newname);
5006
5007 *handle = dlopen(newname, RTLD_NOW);
5008 if(*handle == NULL)
5009 {
5010 strncpy(errorbuf, dlerror(), 1024);
5011 sprintf(newname, "lib%s.so", name);
5012 *handle = dlopen(newname, RTLD_NOW);
5013 }
5014
5015 free(newname);
5016
5017 return (NULL == *handle);
5018 }
5019
5020 /* Queries the address of a symbol within open handle.
5021 * Parameters:
5022 * handle: Module handle returned by dw_module_load()
5023 * name: Name of the symbol you want the address of.
5024 * func: A pointer to a function pointer, to obtain
5025 * the address.
5026 */
5027 int dw_module_symbol(HMOD handle, char *name, void**func)
5028 {
5029 if(!func || !name)
5030 return -1;
5031
5032 if(strlen(name) == 0)
5033 return -1;
5034
5035 *func = (void*)dlsym(handle, name);
5036 return (NULL == *func);
5037 }
5038
5039 /* Frees the shared library previously opened.
5040 * Parameters:
5041 * handle: Module handle returned by dw_module_load()
5042 */
5043 int dw_module_close(HMOD handle)
5044 {
5045 return dlclose(handle);
5046 }
5047
4968 /* 5048 /*
4969 * Returns the handle to an unnamed mutex semaphore. 5049 * Returns the handle to an unnamed mutex semaphore.
4970 */ 5050 */
4971 HMTX dw_mutex_new(void) 5051 HMTX dw_mutex_new(void)
4972 { 5052 {