179512Salfred/* xexit.c -- Run any exit handlers, then exit.
279512Salfred   Copyright (C) 1994-2024 Free Software Foundation, Inc.
379512Salfred
479512SalfredThis file is part of the libiberty library.
579512SalfredLibiberty is free software; you can redistribute it and/or
679512Salfredmodify it under the terms of the GNU Library General Public
779512SalfredLicense as published by the Free Software Foundation; either
879512Salfredversion 2 of the License, or (at your option) any later version.
979512Salfred
1079512SalfredLibiberty is distributed in the hope that it will be useful,
1179512Salfredbut WITHOUT ANY WARRANTY; without even the implied warranty of
1279512SalfredMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1379512SalfredLibrary General Public License for more details.
1479512Salfred
1579512SalfredYou should have received a copy of the GNU Library General Public
1679512SalfredLicense along with libiberty; see the file COPYING.LIB.  If not, write
1779512Salfredto the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
1879512SalfredBoston, MA 02110-1301, USA.  */
1979512Salfred
2079512Salfred/*
2179512Salfred
2279512Salfred@deftypefn Replacement void xexit (int @var{code})
2379512Salfred
2479512SalfredTerminates the program.  If any functions have been registered with
2579512Salfredthe @code{xatexit} replacement function, they will be called first.
2679512SalfredTermination is handled via the system's normal @code{exit} call.
2779512Salfred
2879512Salfred@end deftypefn
2979512Salfred
3079512Salfred*/
3179512Salfred
3279512Salfred#ifdef HAVE_CONFIG_H
3379512Salfred#include "config.h"
3479654Sru#endif
3579512Salfred#include <stdio.h>
3679584Sru#ifdef HAVE_STDLIB_H
3779584Sru#include <stdlib.h>
3879512Salfred#endif
3979574Salfred#include "libiberty.h"
4079512Salfred
4179512Salfred
4279584Sru/* This variable is set by xatexit if it is called.  This way, xmalloc
4379654Sru   doesn't drag xatexit into the link.  */
4479654Sruvoid (*_xexit_cleanup) (void);
4579654Sru
4679654Sruvoid
4779654Sruxexit (int code)
4879654Sru{
4979654Sru  if (_xexit_cleanup != NULL)
5079584Sru    (*_xexit_cleanup) ();
5179584Sru  exit (code);
5279584Sru}
5379584Sru