1 /* $OpenBSD: foo.c,v 1.3 2017/08/07 16:33:52 bluhm Exp $ */ 2 /* Public domain. 2008, Matthieu Herrb */ 3 4 #include <dlfcn.h> 5 #include <stdio.h> 6 #include <err.h> 7 8 static void *h = NULL; 9 10 extern int bar(void); 11 12 void 13 foo_init(void) 14 { 15 printf("loading %s\n", BAR); 16 h = dlopen(BAR, RTLD_LAZY|RTLD_GLOBAL); 17 if (h == NULL) 18 errx(1, "dlopen %s: %s\n", BAR, dlerror()); 19 printf("loaded: %s\n", BAR); 20 } 21 22 int 23 foo(void) 24 { 25 if (h == NULL) 26 foo_init(); 27 28 return bar(); 29 } 30