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