+
+inline static void *
+dlsym_next (const char *symbol)
+{
+ void *sym = dlsym (RTLD_NEXT, symbol);
+ char *str = dlerror ();
+
+ if (str != NULL) {
+ fprintf (stderr, "finding symbol '%s' failed: %s", symbol, str);
+ exit (77);
+ }
+ return sym;
+}
+
+#define WRAP_DLFUNC(_rtype, _func, _args) \
+ _rtype _func _args; \
+ _rtype _func _args { \
+ static _rtype (*_func##_orig) _args = NULL; \
+ if (! _func##_orig ) *(void **) (&_func##_orig) = dlsym_next (#_func);