xexit.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* xexit.c -- Run any exit handlers, then exit.
  2. Copyright (C) 1994-2022 Free Software Foundation, Inc.
  3. This file is part of the libiberty library.
  4. Libiberty is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. Libiberty 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. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with libiberty; see the file COPYING.LIB. If not, write
  14. to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. /*
  17. @deftypefn Replacement void xexit (int @var{code})
  18. Terminates the program. If any functions have been registered with
  19. the @code{xatexit} replacement function, they will be called first.
  20. Termination is handled via the system's normal @code{exit} call.
  21. @end deftypefn
  22. */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include <stdio.h>
  27. #ifdef HAVE_STDLIB_H
  28. #include <stdlib.h>
  29. #endif
  30. #include "libiberty.h"
  31. /* This variable is set by xatexit if it is called. This way, xmalloc
  32. doesn't drag xatexit into the link. */
  33. void (*_xexit_cleanup) (void);
  34. void
  35. xexit (int code)
  36. {
  37. if (_xexit_cleanup != NULL)
  38. (*_xexit_cleanup) ();
  39. exit (code);
  40. }