133965Sjdp/* xexit.c -- Run any exit handlers, then exit.
233965Sjdp   Copyright (C) 1994, 95, 1997 Free Software Foundation, Inc.
333965Sjdp
433965SjdpThis file is part of the libiberty library.
533965SjdpLibiberty is free software; you can redistribute it and/or
633965Sjdpmodify it under the terms of the GNU Library General Public
733965SjdpLicense as published by the Free Software Foundation; either
833965Sjdpversion 2 of the License, or (at your option) any later version.
933965Sjdp
1033965SjdpLibiberty is distributed in the hope that it will be useful,
1133965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1233965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1333965SjdpLibrary General Public License for more details.
1433965Sjdp
1533965SjdpYou should have received a copy of the GNU Library General Public
1633965SjdpLicense along with libiberty; see the file COPYING.LIB.  If not, write
17218822Sdimto the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18218822SdimBoston, MA 02110-1301, USA.  */
1933965Sjdp
2089857Sobrien/*
2189857Sobrien
2289857Sobrien@deftypefn Replacement void xexit (int @var{code})
2389857Sobrien
2489857SobrienTerminates the program.  If any functions have been registered with
2589857Sobrienthe @code{xatexit} replacement function, they will be called first.
2689857SobrienTermination is handled via the system's normal @code{exit} call.
2789857Sobrien
2889857Sobrien@end deftypefn
2989857Sobrien
3089857Sobrien*/
3189857Sobrien
3277298Sobrien#ifdef HAVE_CONFIG_H
3377298Sobrien#include "config.h"
3477298Sobrien#endif
3577298Sobrien#include <stdio.h>
3677298Sobrien#ifdef HAVE_STDLIB_H
3777298Sobrien#include <stdlib.h>
3877298Sobrien#endif
3933965Sjdp#include "libiberty.h"
4033965Sjdp
4133965Sjdp
4233965Sjdp/* This variable is set by xatexit if it is called.  This way, xmalloc
4333965Sjdp   doesn't drag xatexit into the link.  */
44218822Sdimvoid (*_xexit_cleanup) (void);
4533965Sjdp
4633965Sjdpvoid
47218822Sdimxexit (int code)
4833965Sjdp{
4933965Sjdp  if (_xexit_cleanup != NULL)
5033965Sjdp    (*_xexit_cleanup) ();
5133965Sjdp  exit (code);
5233965Sjdp}
53