xref: /openbsd-src/gnu/lib/libiberty/src/xexit.c (revision 150b7e42cfa21e6546d96ae514ca23e80d970ac7)
100bf4279Sespie /* xexit.c -- Run any exit handlers, then exit.
200bf4279Sespie    Copyright (C) 1994, 95, 1997 Free Software Foundation, Inc.
300bf4279Sespie 
400bf4279Sespie This file is part of the libiberty library.
500bf4279Sespie Libiberty is free software; you can redistribute it and/or
600bf4279Sespie modify it under the terms of the GNU Library General Public
700bf4279Sespie License as published by the Free Software Foundation; either
800bf4279Sespie version 2 of the License, or (at your option) any later version.
900bf4279Sespie 
1000bf4279Sespie Libiberty is distributed in the hope that it will be useful,
1100bf4279Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
1200bf4279Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1300bf4279Sespie Library General Public License for more details.
1400bf4279Sespie 
1500bf4279Sespie You should have received a copy of the GNU Library General Public
1600bf4279Sespie License along with libiberty; see the file COPYING.LIB.  If not, write
17*150b7e42Smiod to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18*150b7e42Smiod Boston, MA 02110-1301, USA.  */
1900bf4279Sespie 
2037c53322Sespie /*
2137c53322Sespie 
2237c53322Sespie @deftypefn Replacement void xexit (int @var{code})
2337c53322Sespie 
2437c53322Sespie Terminates the program.  If any functions have been registered with
2537c53322Sespie the @code{xatexit} replacement function, they will be called first.
2637c53322Sespie Termination is handled via the system's normal @code{exit} call.
2737c53322Sespie 
2837c53322Sespie @end deftypefn
2937c53322Sespie 
3037c53322Sespie */
3137c53322Sespie 
3237c53322Sespie #ifdef HAVE_CONFIG_H
3337c53322Sespie #include "config.h"
3437c53322Sespie #endif
3537c53322Sespie #include <stdio.h>
3637c53322Sespie #ifdef HAVE_STDLIB_H
3737c53322Sespie #include <stdlib.h>
3837c53322Sespie #endif
3900bf4279Sespie #include "libiberty.h"
4000bf4279Sespie 
4100bf4279Sespie 
4200bf4279Sespie /* This variable is set by xatexit if it is called.  This way, xmalloc
4300bf4279Sespie    doesn't drag xatexit into the link.  */
44*150b7e42Smiod void (*_xexit_cleanup) (void);
4500bf4279Sespie 
4600bf4279Sespie void
xexit(int code)47*150b7e42Smiod xexit (int code)
4800bf4279Sespie {
4900bf4279Sespie   if (_xexit_cleanup != NULL)
5000bf4279Sespie     (*_xexit_cleanup) ();
5100bf4279Sespie   exit (code);
5200bf4279Sespie }
53