tstatexit.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright (C) 2001-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <dlfcn.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. int
  18. main (void)
  19. {
  20. const char fname[] = "modatexit.so";
  21. void *h;
  22. void (*fp) (void *);
  23. int v = 0;
  24. h = dlopen (fname, RTLD_NOW);
  25. if (h == NULL)
  26. {
  27. printf ("cannot open \"%s\": %s\n", fname, dlerror ());
  28. exit (1);
  29. }
  30. fp = dlsym (h, "foo");
  31. if (fp == NULL)
  32. {
  33. printf ("cannot find \"foo\": %s\n", dlerror ());
  34. exit (1);
  35. }
  36. fp (&v);
  37. if (dlclose (h) != 0)
  38. {
  39. printf ("cannot close \"%s\": %s\n", fname, dlerror ());
  40. exit (1);
  41. }
  42. if (v != 1)
  43. {
  44. puts ("module unload didn't change `v'");
  45. exit (1);
  46. }
  47. puts ("finishing now");
  48. return 0;
  49. }