1 /* Copyright (C) 1991,95,96,97,99,2001,02 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include "set-hooks.h"
26 DEFINE_HOOK (__libc_atexit
, (void))
30 /* Call all functions registered with `atexit' and `on_exit',
31 in the reverse of the order in which they were registered
32 perform stdio cleanup, and terminate program execution with STATUS. */
36 /* We do it this way to handle recursive calls to exit () made by
37 the functions registered with `atexit' and `on_exit'. We call
38 everyone on the list and use the status value in the last
40 while (__exit_funcs
!= NULL
)
42 struct exit_function_list
*old
;
44 while (__exit_funcs
->idx
> 0)
46 const struct exit_function
*const f
=
47 &__exit_funcs
->fns
[--__exit_funcs
->idx
];
54 (*f
->func
.on
.fn
) (status
, f
->func
.on
.arg
);
60 (*f
->func
.cxa
.fn
) (f
->func
.cxa
.arg
, status
);
66 __exit_funcs
= __exit_funcs
->next
;
67 if (__exit_funcs
!= NULL
)
68 /* Don't free the last element in the chain, this is the statically
74 RUN_HOOK (__libc_atexit
, ());
77 extern void _cleanup (void);
84 libc_hidden_def (exit
)