# include # include # include # include "os.h" # ifdef SOLARIS char *libpath[]={"/usr/lib/libc.so","/usr/lib/libsocket.so",NULL}; #define LIBPATH_OK # endif # ifdef Linux char *libpath[]={"/lib/libc.so",NULL}; #define LIBPATH_OK # endif # ifndef LIBPATH_OK # error "Unsupported Architecture" # endif void *dlget(const char *name) { int i=0; void *handle,*ret; while(libpath[i]!=NULL) { handle=dlopen(libpath[i], RTLD_LAZY); if(!handle) { perror("dlopen:"); printf("dlerror: %s\n",dlerror()); } ret = (void *) dlsym(handle,name); dlclose(handle); if(ret) break; i++; } if(libpath[i]==NULL) { perror("dlsym: "); printf("dlerror: %s\n",dlerror()); } assert(ret!=NULL); return ret; } /* void *dlget (const char *name) { void *ret; void *handle = (void *) 0; if (!handle) { if (!(handle = dlopen (libcpath, RTLD_LAZY))) { perror ("dlopen"); exit (1); } } if (!(ret = (void *) dlsym (handle, name))) { perror ("dlopen"); exit (1); } (void) dlclose (handle); handle = (void *) 0; return (ret); } */