xref: /netbsd-src/external/gpl3/gdb/dist/libiberty/xexit.c (revision 5173eb0a33e5d83890ba976253e703be4c92557c)
198b9484cSchristos /* xexit.c -- Run any exit handlers, then exit.
2*5173eb0aSchristos    Copyright (C) 1994-2024 Free Software Foundation, Inc.
398b9484cSchristos 
498b9484cSchristos This file is part of the libiberty library.
598b9484cSchristos Libiberty is free software; you can redistribute it and/or
698b9484cSchristos modify it under the terms of the GNU Library General Public
798b9484cSchristos License as published by the Free Software Foundation; either
898b9484cSchristos version 2 of the License, or (at your option) any later version.
998b9484cSchristos 
1098b9484cSchristos Libiberty is distributed in the hope that it will be useful,
1198b9484cSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1298b9484cSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1398b9484cSchristos Library General Public License for more details.
1498b9484cSchristos 
1598b9484cSchristos You should have received a copy of the GNU Library General Public
1698b9484cSchristos License along with libiberty; see the file COPYING.LIB.  If not, write
1798b9484cSchristos to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
1898b9484cSchristos Boston, MA 02110-1301, USA.  */
1998b9484cSchristos 
2098b9484cSchristos /*
2198b9484cSchristos 
2298b9484cSchristos @deftypefn Replacement void xexit (int @var{code})
2398b9484cSchristos 
2498b9484cSchristos Terminates the program.  If any functions have been registered with
2598b9484cSchristos the @code{xatexit} replacement function, they will be called first.
2698b9484cSchristos Termination is handled via the system's normal @code{exit} call.
2798b9484cSchristos 
2898b9484cSchristos @end deftypefn
2998b9484cSchristos 
3098b9484cSchristos */
3198b9484cSchristos 
3298b9484cSchristos #ifdef HAVE_CONFIG_H
3398b9484cSchristos #include "config.h"
3498b9484cSchristos #endif
3598b9484cSchristos #include <stdio.h>
3698b9484cSchristos #ifdef HAVE_STDLIB_H
3798b9484cSchristos #include <stdlib.h>
3898b9484cSchristos #endif
3998b9484cSchristos #include "libiberty.h"
4098b9484cSchristos 
4198b9484cSchristos 
4298b9484cSchristos /* This variable is set by xatexit if it is called.  This way, xmalloc
4398b9484cSchristos    doesn't drag xatexit into the link.  */
4498b9484cSchristos void (*_xexit_cleanup) (void);
4598b9484cSchristos 
4698b9484cSchristos void
4798b9484cSchristos xexit (int code)
4898b9484cSchristos {
4998b9484cSchristos   if (_xexit_cleanup != NULL)
5098b9484cSchristos     (*_xexit_cleanup) ();
5198b9484cSchristos   exit (code);
5298b9484cSchristos }
53