tst-gconv-init-failure.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Check that module __end_fct is not invoked when the init function fails.
  2. Copyright (C) 2017-2026 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. <https://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <iconv.h>
  17. #include <libgen.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <support/check.h>
  21. #include <support/support.h>
  22. #include <support/test-driver.h>
  23. #include <sys/auxv.h>
  24. /* Test GCONV_PATH to the directory containing the program
  25. executable. */
  26. static void
  27. activate_test_gconv_modules (void)
  28. {
  29. unsigned long ptr = getauxval (AT_EXECFN);
  30. if (ptr == 0)
  31. {
  32. printf ("warning: AT_EXECFN not support, cannot run test\n");
  33. exit (EXIT_UNSUPPORTED);
  34. }
  35. char *test_program_directory = dirname (xstrdup ((const char *) ptr));
  36. TEST_VERIFY (setenv ("GCONV_PATH", test_program_directory, 1) == 0);
  37. free (test_program_directory);
  38. }
  39. static int
  40. do_test (void)
  41. {
  42. activate_test_gconv_modules ();
  43. TEST_VERIFY (iconv_open ("UTF-8", "tst-gconv-init-failure//")
  44. == (iconv_t) -1);
  45. if (errno != ENOMEM)
  46. FAIL_EXIT1 ("unexpected iconv_open error: %m");
  47. return 0;
  48. }
  49. #include <support/test-driver.c>