Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / common / dldb.c
blobcb476b359150e02b33b00477399e918d5c4dbd59
1 /* $NetBSD$ */
3 #include "config.h"
5 #include <dlfcn.h>
7 #include "common.h"
8 #include "pathnames.h"
10 static void relocate __P(());
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; \
22 RELOC(db_create,int,(a,b,c),(DB **, DB_ENV *, u_int32_t),
23 DB**a;DB_ENV*b;u_int32_t c;)
24 RELOC(db_env_create,int,(a,b),(DB_ENV **, u_int32_t),DB_ENV ** a;u_int32_t b;);
25 RELOC(db_strerror,char *,(a),(int),int a;)
27 #define LOADSYM(func) \
28 if ((nvi_##func = dlsym(handle, #func)) == NULL) \
29 goto error;
31 static void
32 relocate()
34 void *handle = dlopen(_PATH_DB3, RTLD_LAZY);
36 if (!handle)
37 goto error;
39 LOADSYM(db_create)
40 LOADSYM(db_env_create)
41 LOADSYM(db_strerror)
43 return;
44 error:
45 fprintf(stderr, "Relocation error: %s\n", dlerror());
46 abort();