tst-cleanup2.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Bao Duong <bduong@progress.com>, 2003.
  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 <setjmp.h>
  16. #include <signal.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <sys/types.h>
  20. static sigjmp_buf jmpbuf;
  21. static void
  22. sig_handler (int signo)
  23. {
  24. siglongjmp (jmpbuf, 1);
  25. }
  26. static int
  27. do_test (void)
  28. {
  29. char *p = NULL;
  30. struct sigaction sa;
  31. sa.sa_handler = sig_handler;
  32. sigemptyset (&sa.sa_mask);
  33. sa.sa_flags = SA_SIGINFO;
  34. if (sigaction (SIGSEGV, &sa, 0))
  35. {
  36. perror ("installing SIGSEGV handler\n");
  37. exit (1);
  38. }
  39. puts ("Attempting to sprintf to null ptr");
  40. if (setjmp (jmpbuf))
  41. {
  42. puts ("Exiting main...");
  43. return 0;
  44. }
  45. sprintf (p, "This should segv\n");
  46. return 1;
  47. }
  48. #define TEST_FUNCTION do_test ()
  49. #include "../test-skeleton.c"