1 /* $NetBSD: dldb.c,v 1.2 2013/11/22 15:52:05 christos Exp $ */ 2 #include "config.h" 3 4 #include <dlfcn.h> 5 6 #include "common.h" 7 #include "pathnames.h" 8 9 static void relocate __P(()); 10 11 #define RELOC(func,returntype,args,proto,types) \ 12 static returntype reloc_##func __P(proto); \ 13 returntype (*nvi_##func) __P(proto) = reloc_##func; \ 14 static returntype reloc_##func args \ 15 types \ 16 { \ 17 relocate(); \ 18 return nvi_##func args; \ 19 } 20 21 RELOC(db_create,int,(a,b,c),(DB **, DB_ENV *, u_int32_t), 22 DB**a;DB_ENV*b;u_int32_t c;) 23 RELOC(db_env_create,int,(a,b),(DB_ENV **, u_int32_t),DB_ENV ** a;u_int32_t b;); 24 RELOC(db_strerror,char *,(a),(int),int a;) 25 26 #define LOADSYM(func) \ 27 if ((nvi_##func = dlsym(handle, #func)) == NULL) \ 28 goto error; 29 30 static void 31 relocate() 32 { 33 void *handle = dlopen(_PATH_DB3, RTLD_LAZY); 34 35 if (!handle) 36 goto error; 37 38 LOADSYM(db_create) 39 LOADSYM(db_env_create) 40 LOADSYM(db_strerror) 41 42 return; 43 error: 44 fprintf(stderr, "Relocation error: %s\n", dlerror()); 45 abort(); 46 } 47