116dce513Schristos /* xexit.c -- Run any exit handlers, then exit.
2*e992f068Schristos Copyright (C) 1994-2022 Free Software Foundation, Inc.
316dce513Schristos
416dce513Schristos This file is part of the libiberty library.
516dce513Schristos Libiberty is free software; you can redistribute it and/or
616dce513Schristos modify it under the terms of the GNU Library General Public
716dce513Schristos License as published by the Free Software Foundation; either
816dce513Schristos version 2 of the License, or (at your option) any later version.
916dce513Schristos
1016dce513Schristos Libiberty is distributed in the hope that it will be useful,
1116dce513Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1216dce513Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1316dce513Schristos Library General Public License for more details.
1416dce513Schristos
1516dce513Schristos You should have received a copy of the GNU Library General Public
1616dce513Schristos License along with libiberty; see the file COPYING.LIB. If not, write
1716dce513Schristos to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
1816dce513Schristos Boston, MA 02110-1301, USA. */
1916dce513Schristos
2016dce513Schristos /*
2116dce513Schristos
2216dce513Schristos @deftypefn Replacement void xexit (int @var{code})
2316dce513Schristos
2416dce513Schristos Terminates the program. If any functions have been registered with
2516dce513Schristos the @code{xatexit} replacement function, they will be called first.
2616dce513Schristos Termination is handled via the system's normal @code{exit} call.
2716dce513Schristos
2816dce513Schristos @end deftypefn
2916dce513Schristos
3016dce513Schristos */
3116dce513Schristos
3216dce513Schristos #ifdef HAVE_CONFIG_H
3316dce513Schristos #include "config.h"
3416dce513Schristos #endif
3516dce513Schristos #include <stdio.h>
3616dce513Schristos #ifdef HAVE_STDLIB_H
3716dce513Schristos #include <stdlib.h>
3816dce513Schristos #endif
3916dce513Schristos #include "libiberty.h"
4016dce513Schristos
4116dce513Schristos
4216dce513Schristos /* This variable is set by xatexit if it is called. This way, xmalloc
4316dce513Schristos doesn't drag xatexit into the link. */
4416dce513Schristos void (*_xexit_cleanup) (void);
4516dce513Schristos
4616dce513Schristos void
xexit(int code)4716dce513Schristos xexit (int code)
4816dce513Schristos {
4916dce513Schristos if (_xexit_cleanup != NULL)
5016dce513Schristos (*_xexit_cleanup) ();
5116dce513Schristos exit (code);
5216dce513Schristos }
53