include curses library in libs when checking curses functionality
[nvi.git] / common / dldb.c
blob292e0ab84ab2bf5e860741d4ac4ea06045b04aa5
1 #include "config.h"
3 #include <dlfcn.h>
5 #include "common.h"
6 #include "pathnames.h"
8 static void relocate __P(());
10 #define RELOC(func,returntype,args,proto,types) \
11 static returntype reloc_##func __P(proto); \
12 returntype (*nvi_##func) __P(proto) = reloc_##func; \
13 static returntype reloc_##func args \
14 types \
15 { \
16 relocate(); \
17 return nvi_##func args; \
20 RELOC(db_create,int,(a,b,c),(DB **, DB_ENV *, u_int32_t),
21 DB**a;DB_ENV*b;u_int32_t c;)
22 RELOC(db_env_create,int,(a,b),(DB_ENV **, u_int32_t),DB_ENV ** a;u_int32_t b;);
23 RELOC(db_strerror,char *,(a),(int),int a;)
25 #define LOADSYM(func) \
26 if ((nvi_##func = dlsym(handle, #func)) == NULL) \
27 goto error;
29 static void
30 relocate()
32 void *handle = dlopen(_PATH_DB3, RTLD_LAZY);
34 if (!handle)
35 goto error;
37 LOADSYM(db_create)
38 LOADSYM(db_env_create)
39 LOADSYM(db_strerror)
41 return;
42 error:
43 fprintf(stderr, "Relocation error: %s\n", dlerror());
44 abort();