12116Sjkh/* xexit.c -- Run any exit handlers, then exit.
22116Sjkh   Copyright (C) 1994-2022 Free Software Foundation, Inc.
32116Sjkh
42116SjkhThis file is part of the libiberty library.
52116SjkhLibiberty is free software; you can redistribute it and/or
62116Sjkhmodify it under the terms of the GNU Library General Public
72116SjkhLicense as published by the Free Software Foundation; either
82116Sjkhversion 2 of the License, or (at your option) any later version.
92116Sjkh
102116SjkhLibiberty is distributed in the hope that it will be useful,
118870Srgrimesbut WITHOUT ANY WARRANTY; without even the implied warranty of
122116SjkhMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
132116SjkhLibrary General Public License for more details.
142116Sjkh
152116SjkhYou should have received a copy of the GNU Library General Public
162116SjkhLicense along with libiberty; see the file COPYING.LIB.  If not, write
1750476Speterto the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
182116SjkhBoston, MA 02110-1301, USA.  */
192116Sjkh
202116Sjkh/*
212116Sjkh
222116Sjkh@deftypefn Replacement void xexit (int @var{code})
2397413Salfred
2497413SalfredTerminates the program.  If any functions have been registered with
252116Sjkhthe @code{xatexit} replacement function, they will be called first.
26152540SbdeTermination is handled via the system's normal @code{exit} call.
272116Sjkh
282116Sjkh@end deftypefn
292116Sjkh
30152540Sbde*/
312116Sjkh
32152540Sbde#ifdef HAVE_CONFIG_H
33152540Sbde#include "config.h"
34152540Sbde#endif
35152540Sbde#include <stdio.h>
36151620Sbde#ifdef HAVE_STDLIB_H
372116Sjkh#include <stdlib.h>
382116Sjkh#endif
392116Sjkh#include "libiberty.h"
402116Sjkh
412116Sjkh
422116Sjkh/* This variable is set by xatexit if it is called.  This way, xmalloc
432116Sjkh   doesn't drag xatexit into the link.  */
442116Sjkhvoid (*_xexit_cleanup) (void);
452116Sjkh
462116Sjkhvoid
472116Sjkhxexit (int code)
482116Sjkh{
492116Sjkh  if (_xexit_cleanup != NULL)
502116Sjkh    (*_xexit_cleanup) ();
512116Sjkh  exit (code);
522116Sjkh}
53