5f7b84
commit 17432d7150bdab3bce2ea66c70ad6c920f54077a
5f7b84
Author: Florian Weimer <fweimer@redhat.com>
5f7b84
Date:   Fri Jun 28 10:15:30 2019 +0200
5f7b84
5f7b84
    support: Add xdlvsym function
5f7b84
5f7b84
diff --git a/support/xdlfcn.c b/support/xdlfcn.c
5f7b84
index f34bb059c00f27f7..b4a6b85649d181c8 100644
5f7b84
--- a/support/xdlfcn.c
5f7b84
+++ b/support/xdlfcn.c
5f7b84
@@ -48,6 +48,26 @@ xdlsym (void *handle, const char *symbol)
5f7b84
   return sym;
5f7b84
 }
5f7b84
 
5f7b84
+void *
5f7b84
+xdlvsym (void *handle, const char *symbol, const char *version)
5f7b84
+{
5f7b84
+  /* Clear any pending errors.  */
5f7b84
+  dlerror ();
5f7b84
+
5f7b84
+  void *sym = dlvsym (handle, symbol, version);
5f7b84
+
5f7b84
+  if (sym == NULL)
5f7b84
+    {
5f7b84
+      const char *error = dlerror ();
5f7b84
+      if (error != NULL)
5f7b84
+        FAIL_EXIT1 ("error: dlvsym: %s\n", error);
5f7b84
+      /* If there was no error, we found a NULL symbol.  Return the
5f7b84
+         NULL value in this case.  */
5f7b84
+    }
5f7b84
+
5f7b84
+  return sym;
5f7b84
+}
5f7b84
+
5f7b84
 void
5f7b84
 xdlclose (void *handle)
5f7b84
 {
5f7b84
diff --git a/support/xdlfcn.h b/support/xdlfcn.h
5f7b84
index 5ab7494e70924f52..ab1cbb3cb9bb1cc7 100644
5f7b84
--- a/support/xdlfcn.h
5f7b84
+++ b/support/xdlfcn.h
5f7b84
@@ -26,6 +26,7 @@ __BEGIN_DECLS
5f7b84
 /* Each of these terminates process on failure with relevant error message.  */
5f7b84
 void *xdlopen (const char *filename, int flags);
5f7b84
 void *xdlsym (void *handle, const char *symbol);
5f7b84
+void *xdlvsym (void *handle, const char *symbol, const char *version);
5f7b84
 void xdlclose (void *handle);
5f7b84
 
5f7b84