xdlfcn.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Support functionality for using dlopen/dlclose/dlsym.
  2. Copyright (C) 2017-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <stddef.h>
  16. #include <support/check.h>
  17. #include <support/xdlfcn.h>
  18. void *
  19. xdlopen (const char *filename, int flags)
  20. {
  21. void *dso = dlopen (filename, flags);
  22. if (dso == NULL)
  23. FAIL_EXIT1 ("error: dlopen: %s\n", dlerror ());
  24. /* Clear any errors. */
  25. dlerror ();
  26. return dso;
  27. }
  28. void *
  29. xdlsym (void *handle, const char *symbol)
  30. {
  31. void *sym = dlsym (handle, symbol);
  32. if (sym == NULL)
  33. FAIL_EXIT1 ("error: dlsym: %s\n", dlerror ());
  34. /* Clear any errors. */
  35. dlerror ();
  36. return sym;
  37. }
  38. void
  39. xdlclose (void *handle)
  40. {
  41. if (dlclose (handle) != 0)
  42. FAIL_EXIT1 ("error: dlclose: %s\n", dlerror ());
  43. /* Clear any errors. */
  44. dlerror ();
  45. }