xref: /dflybsd-src/contrib/binutils-2.34/libiberty/xexit.c (revision b52ef7118d1621abed722c5bbbd542210290ecef)
1*fae548d3Szrj /* xexit.c -- Run any exit handlers, then exit.
2*fae548d3Szrj    Copyright (C) 1994-2020 Free Software Foundation, Inc.
3*fae548d3Szrj 
4*fae548d3Szrj This file is part of the libiberty library.
5*fae548d3Szrj Libiberty is free software; you can redistribute it and/or
6*fae548d3Szrj modify it under the terms of the GNU Library General Public
7*fae548d3Szrj License as published by the Free Software Foundation; either
8*fae548d3Szrj version 2 of the License, or (at your option) any later version.
9*fae548d3Szrj 
10*fae548d3Szrj Libiberty is distributed in the hope that it will be useful,
11*fae548d3Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
12*fae548d3Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*fae548d3Szrj Library General Public License for more details.
14*fae548d3Szrj 
15*fae548d3Szrj You should have received a copy of the GNU Library General Public
16*fae548d3Szrj License along with libiberty; see the file COPYING.LIB.  If not, write
17*fae548d3Szrj to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18*fae548d3Szrj Boston, MA 02110-1301, USA.  */
19*fae548d3Szrj 
20*fae548d3Szrj /*
21*fae548d3Szrj 
22*fae548d3Szrj @deftypefn Replacement void xexit (int @var{code})
23*fae548d3Szrj 
24*fae548d3Szrj Terminates the program.  If any functions have been registered with
25*fae548d3Szrj the @code{xatexit} replacement function, they will be called first.
26*fae548d3Szrj Termination is handled via the system's normal @code{exit} call.
27*fae548d3Szrj 
28*fae548d3Szrj @end deftypefn
29*fae548d3Szrj 
30*fae548d3Szrj */
31*fae548d3Szrj 
32*fae548d3Szrj #ifdef HAVE_CONFIG_H
33*fae548d3Szrj #include "config.h"
34*fae548d3Szrj #endif
35*fae548d3Szrj #include <stdio.h>
36*fae548d3Szrj #ifdef HAVE_STDLIB_H
37*fae548d3Szrj #include <stdlib.h>
38*fae548d3Szrj #endif
39*fae548d3Szrj #include "libiberty.h"
40*fae548d3Szrj 
41*fae548d3Szrj 
42*fae548d3Szrj /* This variable is set by xatexit if it is called.  This way, xmalloc
43*fae548d3Szrj    doesn't drag xatexit into the link.  */
44*fae548d3Szrj void (*_xexit_cleanup) (void);
45*fae548d3Szrj 
46*fae548d3Szrj void
xexit(int code)47*fae548d3Szrj xexit (int code)
48*fae548d3Szrj {
49*fae548d3Szrj   if (_xexit_cleanup != NULL)
50*fae548d3Szrj     (*_xexit_cleanup) ();
51*fae548d3Szrj   exit (code);
52*fae548d3Szrj }
53