summaryrefslogtreecommitdiff
path: root/support/xdlfcn.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2019-12-16 21:19:30 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-12-16 21:19:30 +0100
commit10f1958417a4944a60a08230eae6a639209d52f8 (patch)
tree7662166d1cf40507e65fba6dbb9ee73a7c652afc /support/xdlfcn.c
parent963c37d5c0eb62b38f8764b23931c0dcdd497a13 (diff)
parenta2e487ce1c59d19345d9ecacc58de79febd869e4 (diff)
Merge branch 'master' of git://sourceware.org/git/glibc into upstreamupstream
Diffstat (limited to 'support/xdlfcn.c')
-rw-r--r--support/xdlfcn.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/support/xdlfcn.c b/support/xdlfcn.c
index f34bb059c0..ec15b1599a 100644
--- a/support/xdlfcn.c
+++ b/support/xdlfcn.c
@@ -1,5 +1,5 @@
/* Support functionality for using dlopen/dlclose/dlsym.
- Copyright (C) 2017-2018 Free Software Foundation, Inc.
+ Copyright (C) 2017-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -14,7 +14,7 @@
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <stddef.h>
#include <support/check.h>
@@ -28,23 +28,46 @@ xdlopen (const char *filename, int flags)
if (dso == NULL)
FAIL_EXIT1 ("error: dlopen: %s\n", dlerror ());
- /* Clear any errors. */
- dlerror ();
-
return dso;
}
void *
xdlsym (void *handle, const char *symbol)
{
+ /* Clear any pending errors. */
+ dlerror ();
+
void *sym = dlsym (handle, symbol);
if (sym == NULL)
- FAIL_EXIT1 ("error: dlsym: %s\n", dlerror ());
+ {
+ const char *error = dlerror ();
+ if (error != NULL)
+ FAIL_EXIT1 ("error: dlsym: %s\n", error);
+ /* If there was no error, we found a NULL symbol. Return the
+ NULL value in this case. */
+ }
+
+ return sym;
+}
- /* Clear any errors. */
+void *
+xdlvsym (void *handle, const char *symbol, const char *version)
+{
+ /* Clear any pending errors. */
dlerror ();
+ void *sym = dlvsym (handle, symbol, version);
+
+ if (sym == NULL)
+ {
+ const char *error = dlerror ();
+ if (error != NULL)
+ FAIL_EXIT1 ("error: dlvsym: %s\n", error);
+ /* If there was no error, we found a NULL symbol. Return the
+ NULL value in this case. */
+ }
+
return sym;
}
@@ -53,7 +76,4 @@ xdlclose (void *handle)
{
if (dlclose (handle) != 0)
FAIL_EXIT1 ("error: dlclose: %s\n", dlerror ());
-
- /* Clear any errors. */
- dlerror ();
}